I am looking for a way to design a system that can provide a linear and incremental counting for invoice number accros a scalable system.
At this time, I have four pools of two servers (two pool for europe and two pool for america -> total eight servers ). This system handle sports subscriptions and can generate invoice at two moment :
When the customer subscribes for the first time, all along the day, especially before a match or a sport event
When the subscription comes at his until date and renew, we run a batch that seeks all subscriptions to renew at the rate/parallelization we want.
All theses subscriptions are distribued through an amqp and federated exchanges , e.g : pool1 handle all subscriptions coming from the load balancer (lb1) and put them into a queue (queue_pool1), then later, the queue is depiled by servers of pool1 and subscriptions are handled into pool1, except when the queue_pool1 is full, so the excess messages go into the federated exchange that feeds queue to the exchange of the pool2 (queue_pool2).
At this time, we use a linear counting based on a timestamp +micro seconds base10 to 36, when we generate it, we put it on a shared memcached and a check is provided into this memcached before using the number invoice generated, but for legal purpose we have to change it to an incremental counter. However, we can use a dedicated counter with a prefixed indicator like this I1-NNNNNNN, I2-NNNNNNNN, but not holes between numbers invoices. etc. (Best would be an unique counter for all servers.)
When we run renews, the rate is around 20/40 subscriptions in parallel. Depending on our partner api payment, we are at 10-20 renews per seconds. We can control the rate.
When we have a big event, we are around 5 to 10 subscriptions per seconds. We can control the rate but if the rate is too slow, customers will expect delay into their services activation.
Each pool handle almost around 1000 requests per second for all incoming traffic.