Why use a database

Game development with Board Game Arena Studio
Post Reply
Swinkels
Posts: 8
Joined: 08 November 2021, 14:47

Why use a database

Post by Swinkels »

Sorry for the naïeve question, but what's the point in storing small amounts of data in a database when you can store them in php memory instead? It seems like php memory is way faster than db queries.

Is it true that the server thread might die and another thread needs to be able to recover the state from the db?

Currently, I maintain a cached version of a db table in memory, and make insert/delete/update queries when information changes. To access information, I use the cache as long as it is defined. If not, I select all from the database to restore the cache.

Is this the proper way of doing it? How long does a cached object exist? The entire game? Just a single action? Do multiple independent server threads manage the php based on availability?
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: Why use a database

Post by RicardoRix »

Nothing persists in php memory between calls, which is why the whole game state and data is stored in a db.

Normally you just query and update the db as and when required.
imralav
Posts: 44
Joined: 02 February 2024, 08:56

Re: Why use a database

Post by imralav »

I don't think we have the same instance shared between the calls. I believe each call is handled separately, with clear memory state, so it is always loading stuff from database anyway.
Swinkels
Posts: 8
Joined: 08 November 2021, 14:47

Re: Why use a database

Post by Swinkels »

Thanks! I already suspected that, but I just wanted to verify it.
imralav
Posts: 44
Joined: 02 February 2024, 08:56

Re: Why use a database

Post by imralav »

Considering the above, I like the approach to load all necessary data upfront in a single call, modify it if necessary. And only persist it at the end of the processing, instead of hitting the DB multiple times on each request. You probably already have something similar.
Post Reply

Return to “Developers”