In an authoritative game server working with websockets, should you store every action to the database before sending the response to the client? The risk is the slow response time.

Or should the result be calculated with variables we cached earlier and cache the result to update the cache to the database once in a while? But with a risk that data can be lost if the server crashes before it's stored into the database.

For a game server handling up to 500 players at the same time and up to 16 request by seconds with no heavy calculations, what should be decided?

  • \$\begingroup\$ It sounds like you understand the trade-offs you're making between speed and persistence. Now it's up to your profiling, to determine whether synchronous database updates are fast enough for your needs, or whether regular checkpointing is persistent enough for your needs. \$\endgroup\$
    – DMGregory
    Nov 6, 2020 at 17:02

1 Answer 1


Sending the data to the client before you are sure that it was successfully stored in the database, you run the risk that the client will display information to the user that the server ultimately will disagree with eventually. You should consider on a case-by-case basis if the consequence of a user potentially seeing this "incorrect" information, is greater than the consequence of the user having to wait slightly longer.

Typically for transactional kinds of information, e.g. spending resources, sending a message or saving progress, it is a lot more important for the user to be assured that the information is actually true than it is to know the information 100 milliseconds sooner.

For fast-updating information that is quickly invalidated by something new, e.g. the position of a player that is moving around a world, the slower you get that information to the user, the less valuable it is (due to how frequently it changes). Also, the individual importance of each update is likely much smaller, and thus the consequence of it being incorrect is much lower. In some critical cases, every moment of unnecessary delay will make your client application feel less responsive and degrade the user experience.

See also: https://en.wikipedia.org/wiki/Client-side_prediction


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .