A developer is designing a serverless multi-tenant web application where an AWS Lambda function processes incoming user requests. The application must maintain session state for users across subsequent HTTP requests. During initial testing under high concurrency, the developer notices that session data is frequently lost between requests. The session state must persist reliably, scale automatically, and support automatic expiration of sessions after 30 minutes of inactivity. Which of the following database or caching strategies should the developer implement to resolve this issue?
- Store session state in Amazon DynamoDB with Time to Live (TTL) enabled, using a unique session ID as the partition key.Answer
- BStore session state in a global variable within the Lambda function's execution context to reuse cached data across subsequent invocations.
- CStore session state in AWS Systems Manager Parameter Store with SecureString parameters, using a TTL parameter policy to expire sessions.
- DStore session state in Amazon DynamoDB and run a cron-triggered Scan operation filtered by a session timestamp to purge expired sessions.
Answer
Store session state in Amazon DynamoDB with Time to Live (TTL) enabled, using a unique session ID as the partition key.
Storing session state in Amazon DynamoDB with TTL enabled and using a unique session ID as the partition key provides a highly scalable, key-value lookup mechanism that natively handles session expiration at no additional cost. DynamoDB automatically deletes expired items, which minimizes table size and prevents performance degradation, satisfying the 30-minute inactivity requirement.
Step-by-Step Solution
Key Concept
Session State Management in Serverless Architectures using DynamoDB TTL
Estimated Time:2m 0s