Soru

Zorluk: OrtaApplication Caching and Session State Management

A team is building a serverless document collaboration portal where users edit documents concurrently. The portal needs to manage transient user presence indicators (e.g., 'User X is online') that expire automatically after 5 minutes of user inactivity. The developer wants to minimize storage costs and avoid running unnecessary compute resources to clean up expired session records. Which approach should the developer take to meet these requirements?

  1. A
    Store the presence states in AWS Systems Manager Parameter Store and query the parameters using the AWS SDK.
  2. B
    Store the presence states in Amazon DynamoDB and configure a cron-triggered AWS Lambda function to run a Scan operation to find and delete expired records.
  3. Store the presence states in an Amazon DynamoDB table and enable Time to Live (TTL) on a timestamp attribute representing the expiration time.Cevap
  4. D
    Store the presence states in the local memory of the backend AWS Lambda functions and increase the Lambda timeout duration to preserve the execution context.

Cevap

Store the presence states in an Amazon DynamoDB table and enable Time to Live (TTL) on a timestamp attribute representing the expiration time.
The correct approach is to store the presence states in an Amazon DynamoDB table and enable Time to Live (TTL). DynamoDB TTL allows developers to define a timestamp attribute indicating when an item should expire. DynamoDB automatically deletes these items in the background, typically within 48 hours of expiration, without consuming provisioned read or write throughput. This completely eliminates the need for custom clean-up code, minimizes storage costs, and scale-out overhead.

Adım Adım Çözüm

1
Identify the nature of the application data.
The presence indicators represent transient, high-velocity session-like state data.
Understanding the access pattern and lifecycle of the data helps select the most cost-effective storage and cleanup strategy.
2
Evaluate the requirement for automatic, resource-efficient deletion of data after 5 minutes.
DynamoDB Time to Live (TTL) automatically identifies and purges expired items at no additional cost and without consuming throughput.
This avoids custom scheduled cleanup scripts (like cron-triggered Lambda functions running scans) which consume read capacity and compute resources.
3
Rule out storage solutions that are not designed for transient user states or that lack persistence guarantees.
Systems Manager Parameter Store is for configuration/secrets, and Lambda local memory does not persist state reliably.
This ensures the architecture conforms to AWS best practices for state management and serverless design.

Anahtar Kavram

Session state expiration using Amazon DynamoDB Time to Live (TTL)
Bu soruyu puanla