SAA-C03 Question 114
Single answerYou are designing a microservices-based architecture for a new e-commerce application that handles frequent user sessions and shopping cart data. Which design approach should you follow to ensure scalability and fault tolerance in the application?
- A
Store session state and shopping cart data in the microservice's memory to reduce latency.
- B
Use a distributed cache or database to store session state and shopping cart data for scalability.
- C
Design microservices to maintain user session states locally to avoid external dependencies.
- D
Use a stateful design for microservices to maintain a persistent connection with the client.
Show answer and explanation
Correct answer: B
Explanation
Microservices should be designed to be stateless whenever possible to maximize scalability and fault tolerance. For scenarios requiring state management, such as session state or shopping cart data, an external distributed cache or database (e.g., Amazon ElastiCache or DynamoDB) should be used. This ensures that data is not tied to any specific microservice instance and can be accessed by other instances if needed.
- A. Incorrect.
Storing session state and shopping cart data in the microservice's memory is not scalable because the data is tied to a specific instance. If the instance is terminated or restarted, the state would be lost.
- B. Correct.
Using a distributed cache or database allows session state and shopping cart data to be centralized and accessible across multiple instances, enabling scalability and fault tolerance.
- C. Incorrect.
Maintaining user session states locally in microservices limits scalability and increases the risk of data loss if a microservice instance fails or is terminated.
- D. Incorrect.
Stateful designs are generally avoided in microservices architectures as they reduce scalability and fault tolerance by requiring persistent connections between clients and specific service instances.