Ramon
Ramon

Reputation: 409

Queue requests for each client

My backend system serves about 10K POS devices, each device will request service in a sequential style, however I am wondering how the backend guarantee to handle requests of a given client in sequential style.

For example a device issues a 'sell' request, and timeout(may DB blocked) to get response, so it issue a 'cancellation' to cancel that sale request. In this case, the backend may is still handling 'sale' transaction when get 'cancellation' request, it may cause some unexpected result.

My idea is to setup a persistent queue for each device(client), but is it OK to setup 10K queues? I am not sure, please help.

Upvotes: 0

Views: 67

Answers (1)

Nicole
Nicole

Reputation: 33197

This is an incredibly complex area of computer science and a lot of these problems have been solved many times. I would not try to reinvent the wheel.

My advice:

  • Read about and thoroughly understand ACID (summaries paraphrased):
    • Atomicity - If any part of a transaction fails, the whole transaction fails, and the database is not left in an unknown or corrupted state. This is hugely important. Rely on existing software to make this happen in the actual database. And don't invent data structures that require you to reinvent your own transaction system. Make your transactions as small as possible to reduce failures.
    • Consistency - The database is never left in an invalid state. All operations committed to it will take it to a new valid state.
    • Isolation - The operations you perform on a database can be performed at the same time and result in the same state as if performed one after the other. OR performed safely inside a locking transaction.
    • Durability - Once a transaction is committed, it will remain so.

Both your existing system and your proposed idea sound like they could potentially be violating ACID:

  • A stateful request system probably violates (or makes it hard not to violate) isolation.
  • A queue could violate durability if not done in a bullet-proof way.

Not to mention, you have scalability issues as well. Combine scalability and ACID and you have heavyweight situation requiring serious expertise.

If you can help it, I would strongly suggest relying on existing systems, especially if this is for point of sale.

Upvotes: 1

Related Questions