What can be stored (per user) in memory on a HTTP server

My first programming language is PHP, which results in a stateless webserver. Each request you have to rebuild your state.

Now that I’m happily doing Go, I want to give a shot at creating a webbased browser game. I can keep state/data in memory; good candidates are game-wide structs.

But my question is; Can/should per-user data be stored in memory?

Pros: Things will be fast, I won’t have to do (as much) database transactions
Cons: It won’t scale well with lots of concurrent users

For a starting game the ‘concurrent user’ issue is probably a non-issue. The ‘will be fast’ is also quite relative, as the frontend will have JS and images and browsers still take more time rendering.

I understand this is quite a big ‘It Depends’ question, but I’m curious about examples/thoughts out there.

My first thought: Use a persistent cache, or a database with a cache layer. This way, frequently used data is available from memory while unused data can be removed from the cache (thus addressig the scalability part).

(Here I initially added some “it depends” thoughts but I figured they would not add anything substantial :slight_smile: )


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.