Monday, 2 September 2013

Multitenant System with Sequences (on Azure)

Multitenant System with Sequences (on Azure)

I'm trying to utilize of the most elegant solution or use the lightest
library to try and generate sequences for particular records. This will be
a multitenant system hosted in Azure using SQL Azure. All the tenants will
share the same database. It is an ASP MVC4 application.
Tenant A and Tenant B both add in two different Expenses. Each record will
get a unique id (perhaps an INT or a GUID) that the system will use,
however, each record needs a Tenant-Human-Readable ID that is an int also
that increments for each tenant. Why? It would be nice for each tenant to
have their own incrementing number that they can relate to. Think of an
Invoice Number, perhaps.
Eg,
Tenant A adds an expense. PKEY = 1 / Sequence = 1
Tenant B adds an expense. PKEY = 2 / Sequence = 1
Tenant A adds an expense. PKEY = 3 / Sequence = 2
One solution would be to keep a table that would have the Sequence Type,
Tenant ID, and Next Value and just query it & increment it right before I
insert an Expense (to use the same example). This seems like setting
myself up for some poor database performance in the long term.
Is there another technique or perhaps a library that can help out in this
situation?

No comments:

Post a Comment