I am currently writing an application that is going to be an adaptive quiz-like site for studying. The idea is a user is studying some topic and they are given questions on the site and enter their answers. As they enter in answers, the site's backend does some logic to compare the questions they missed with the rest of the question bank to decide what the best question to give them next.

My question is whether I should continue using the AWS Lambda backend I have been using for the rest of the site or whether I need some sort of stateful backend. My thoughts are that with a stateful backend, I could store some user session data that I can update with each question they do. With the lambda, I would have to store question in the database with each update and query the database each time because the backend holds no state.

Would these constant queries slow down my application? How much? I would like to keep my current lambda backend if it is possible but don't want to do so if it will lead me to issues later on.

  • dont try to hold state in memory, it fails as soon as you have more than one box, or too many users
    – Ewan
    Commented Dec 5, 2023 at 21:00
  • Rather than telling you what the answer should be and expecting you to dogmatically follow it; I strongly suggest you read up on the benefits of stateful/stateless services and really consider the pros and the cons here. You wouldn't want to make a decision based on a pro that pales in comparison to the cons that you've signed yourself up for.
    – Flater
    Commented Dec 5, 2023 at 23:20

2 Answers 2


Would these constant queries slow down my application? How much?

I've learned the hard way over many years to measure a performance problem first before trying to solve it. Even if you measure a performance problem, you should do some minimal profiling of the application to pinpoint the part of the application that runs slow. Relational databases have spent 30+ years optimizing for what-if performance issues. In general, you shouldn't.

Introducing session data gets tricky, as Ewan mentioned in a comment — and this all depends on how session storage is implemented.

If session data is stored on a single machine or in a single container, then each container ends up with copies of the same information. Depending on load balancer configurations or how clusters of containers are configured, requests could land on random instances of your application. This defeats the purpose of loading data into a session.

You can configure shared session stores, but that just introduces another component to your system that basically acts as a shared key-value database.

My best advice is to query the database as needed. Keep your application as simple as possible. Only after measuring and pinpointing a performance problem should you think about optimizations. Even then, the problem might not be solved with caching things in a session. Performance problems should be addressed on an individual basis. There aren't many universal solutions to performance problems.

  • "The AWS Lambda backend persists data to a database, therefore it is already stateful, in my opinion." The stateful/stateless attribute is generally used to refer to the application's runtime, not the existence of some external component that persists data. "External" is a key component of that statement. If you deploy your app in X instances, and every individual instance gets its own persistence store; that's stateful. If there's one shared database server and all your app instances connect to that same server, that's an external component.
    – Flater
    Commented Dec 5, 2023 at 23:23
  • The whole stateless front end deal was to make it easy to spot memory leaks. If the design says the memory footprint should be constant you know you have a problem when it's not. When you want long uptimes you need code that doesn't leak. By making state the DB's problem you push that problem out of your code. We talked about that here. Commented Dec 6, 2023 at 15:28

State doesn't need to be stored on the server side and retrieved on each request. Instead, if possible, consider storing the state in the client and providing it to the server on each request (and the server sends updated, signed state back to the client on each response).

This can only really work if the size of the state is manageable but it can be used to great effect, and ensures that you can horizontally scale the servers without worrying about having to store session state in any kind of database.

  • This could be an option for something simple like a quiz application. This moves a good amount of the logic into the client. If I understand correctly, the "signed state" means you include some sort of checksum with the response so the server can compare it to future requests. Is that what you're thinking? Commented Dec 11, 2023 at 23:39
  • @GregBurghardt yep. Commented Dec 12, 2023 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.