Generating sequential numbers in multi-user saas application

后端 未结 6 1798
野趣味
野趣味 2021-02-08 20:52

How do people generate auto_incrementing integers for a particular user in a typical saas application?

For example, the invoice numbers for all the invoices for a partic

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-08 21:23

    If the invoice numbers are independent for each user/customer then it seems like having "lastInvoice" field in some persistent store (eg. DB record) associated with the user is pretty unavoidable. However this could lead to some contention for the "latest" number.

    Does it really matter if we send a user invoices 1, 2, 3 and 5, and never send them invoice 4? If you can relax the requirement a bit.

    If the requirement is actually "every invoice number must be unique" then we can look at all the normal id generating tricks, and these can be quite efficient.

    Ensuring that the numbers are sequenctial adds to the complexity, does it add to the business benefit?

提交回复
热议问题