Question

Difficulty: HardApplication Caching and Session State Management

A developer is designing a stateful web application that will be hosted on Amazon ECS across multiple Availability Zones. The application requires a shared, external session store to maintain user shopping carts. The session store must support sub-millisecond read/write latency, accommodate complex data structures such as lists and hashes for cart items, and automatically expire session records after 2 hours of inactivity to control costs. Additionally, the solution must survive cache node failures without losing user session data.

Which solution should the developer implement to meet these requirements?

  1. Use Amazon ElastiCache for Redis with Multi-AZ and automatic failover enabled, and configure the application to store shopping cart data in Redis hashes with a Time-To-Live (TTL) of 7200 seconds.Answer
  2. B
    Use Amazon DynamoDB to store shopping cart data, and write a scheduled background worker that runs a weekly Scan operation on the table to identify and delete inactive shopping carts older than 2 hours.
  3. C
    Use Amazon DynamoDB to store shopping cart data, configuring a single static string value as the partition key and the user session ID as the sort key to keep all active carts grouped in a single partition for rapid retrieval.
  4. D
    Use AWS Systems Manager Parameter Store to store user session data as SecureString parameters, and apply a Parameter Policy with a TTL of 120 minutes to automatically delete expired sessions.

Answer

Use Amazon ElastiCache for Redis with Multi-AZ and automatic failover enabled, and configure the application to store shopping cart data in Redis hashes with a Time-To-Live (TTL) of 7200 seconds.
The correct solution uses Amazon ElastiCache for Redis because it supports sub-millisecond latencies, provides advanced data structures (like Redis hashes) to represent shopping cart items, and offers high availability through replication groups, Multi-AZ, and automatic failover. Setting a TTL of 7200 seconds ensures that keys expire automatically after 2 hours of inactivity.

Step-by-Step Solution

1
Analyze the requirements for latency and data structures.
The application requires sub-millisecond read/write latency and supports complex data structures (lists and hashes). Amazon ElastiCache (specifically Redis) is designed for in-memory, sub-millisecond lookups and supports advanced data structures natively.
Memcached only supports simple strings, whereas Redis supports hashes, lists, and sets, which are ideal for shopping carts.
2
Evaluate high availability and failover requirements.
The session store must survive cache node failures. Selecting an ElastiCache for Redis replication group with Multi-AZ and automatic failover ensures that a replica is promoted to primary with minimal downtime if the primary node fails.
Without Multi-AZ failover, a node failure would cause data loss and application disruption.
3
Address the session expiration requirement.
Configure a Time-To-Live (TTL) of 7200 seconds (2 hours) on the Redis keys when writing session data.
Redis handles key expiration automatically in the background, freeing up memory without requiring custom application clean-up workers.

Key Concept

Selecting ElastiCache for Redis for high-availability session state management with complex data structures and automatic key eviction (TTL).
Rate this question