'How to improve the delay in live auction (bidding) system

I am currently trying to develop a live auction system and struggling to come up with the best approach to achieve it. The auction system needs to have the following features.

  • the remaining seconds should be displayed and be synchronized on all participants’ devices.
  • the remaining seconds should be incremented when bids are made. The incremented value changes based on the current remaining seconds (eg : increment 10 seconds if the current remaining seconds is less than 10 seconds, otherwise increment 30)
  • auctions should end instantly when time is up

Below is the current approach.

  1. Bidding request is made from client to Rails server to create bid data
  2. auction_end_at value is incremented based on the remaining seconds and is posted to Firestore.
  3. Client side then receives the incremented auction_end_at from Firestore and calculate the remaining seconds comparing with new Date() and displays it. This is done every second to execute the countdown.
  4. The auction ends when the remaining seconds equals to zero and bidding buttons are hidden.

The problem with the approach.

Since there is a delay between creating a bidding request and client side receiving the incremented auction_end_at, the auction ends on client side (the client side countdown logic continues when processing the server side code and the remaining seconds becomes zero.) when people bid in the very last second.

Other approaches I have considered

  • Remove Rails. By writing data from client side to Firestore directly should reduce the latency time. With this approach, the client side needs to have the incrementing the auction_end_at logic and does not seem like the best approach in terms of security reasons. (anyone can update the auction_end_at value)
  • Using Cloud functions instead of Rails. Maybe faster than Rails?

I am stuck with this problem for a few days now, not being able to come up with the best approach. Any help would be very much appreciated. Thanks a lot in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source