Monday 8 May 2017

What's the best way to cache session data in Node?

Our app (Node / Express) has some data that is generated during a user session, and we need to have quick access to it. I was wondering what the best way to do this might be.For more detail:The initial data is requested from an external server, then processed. It is this processed result that we must store as long as the user's in session.Data size should be about 10kb of size per user on average, 25kb per user tops. Hopefully one day we'll have hundreds or thousands of concurrent users, so it'd be great to design with that ambition in mind.We need very quick access to it - we might want to feed it back to the user dozens of times per session.It definitely needs to live in the server and not in the client, as it is used in processes there.We might want to store it into a database some day after the session has ended, but for now the priority is to have something that is only persistent for the duration of the user session.I have explored a couple options, including:express-session + Redisnode-cacheI am still a beginner so there are some questions you might be able to help me with:What's the best method in your experience? Any obvious ones we've skipped? Any trade-offs we should be aware of?Why is Redis such a popular system for this? In my novice mind this seems like a rather simple operation (just write some data to system memory, and delete it on certain conditions), so I'm wondering why one would layer another system into their stack, instead of simply reading and writing from/into memory with the help of a package.Thanks in advance for your help.

Submitted May 08, 2017 at 12:29PM by no_pants_gamer

No comments:

Post a Comment