I’m working on the backend design for an on-demand application where customers can request a service and nearby providers can accept the request.

I’m currently trying to understand how to prevent race conditions when multiple customers request the same provider at nearly the same time.

For example, if two booking requests arrive within a few milliseconds:

How should the database handle the two transactions?
Is database locking enough, or should I use another approach?
Would Redis be useful for managing provider availability?
Should the booking status be updated through a REST API, WebSocket, or both?
How can I make sure the customer receives an accurate booking status in real time?

I’d appreciate advice from developers who have implemented similar concurrent booking or reservation systems.

Salem commented: Same question spammed multiple times +0

Recommended Answers

All 3 Replies

I’m currently trying to understand how to prevent race conditions when multiple customers request the same provider at nearly the same time.

Do you need to?

  • you send all the requests to the provider.
  • provider chooses one customer, and sends that back to you
  • you tell the winning customer, "congratulations"
  • you tell all others, "sorry", even to requests that haven't been sent out yet to the provider
commented: Winner! +0

I’d appreciate advice from developers who have implemented similar concurrent booking or reservation systems.

My top tip for implementing concurrent booking systems, is do not implement a concurrent booking system.

Keep your request processing sequential, aka serial, aka single threaded, and you will never have to deal with any of the problems you foresee in your original description.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.