Soru

Zorluk: ZorApplication Caching and Session State Management

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?

  1. Store session state in Amazon DynamoDB with Time to Live (TTL) enabled, using a unique session ID as the partition key.Cevap
  2. B
    Store session state in a global variable within the Lambda function's execution context to reuse cached data across subsequent invocations.
  3. C
    Store session state in AWS Systems Manager Parameter Store with SecureString parameters, using a TTL parameter policy to expire sessions.
  4. D
    Store session state in Amazon DynamoDB and run a cron-triggered Scan operation filtered by a session timestamp to purge expired sessions.

Cevap

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.

Adım Adım Çözüm

1
Analyze the application requirements: session persistence must survive concurrent requests, scale automatically, and support automated cleanup after 30 minutes of inactivity.
Determine that local memory storage within Lambda is unsuitable because Lambda execution contexts are isolated, ephemeral, and dynamically recycled under load.
To ensure reliable session persistence, session data must be written to an external, centralized datastore rather than the local execution context.
2
Select a centralized database solution that supports low-latency lookups and native scaling.
Amazon DynamoDB is chosen because using the session ID as a partition key provides O(1)O(1) key-value read and write performance that scales horizontally.
DynamoDB is the AWS best practice for serverless session state storage because it handles high concurrency with minimal administrative overhead.
3
Incorporate the session cleanup/expiration requirement into the DynamoDB configuration.
Enable Time to Live (TTL) on the DynamoDB table and designate an attribute representing the expiration timestamp (30 minutes30\text{ minutes} in the future).
DynamoDB handles the background deletion of expired items automatically and for free, avoiding the need for expensive and resource-intensive Scan operations.

Anahtar Kavram

Session State Management in Serverless Architectures using DynamoDB TTL
Tahmini Süre:2m 0s
Bu soruyu puanla