ElastiCache Valkey
After this you can answer: What does the cache hold, and what happens to MiniTickets when it disappears?
Picture it
Section titled “Picture it”flowchart TB API["api tasks<br/>use api-sg"] -->|"rediss:// TCP 6379"| V[("minitickets-dev-valkey")] V --- S["sessions"] V --- C["events cache"] V --- R["rate limits"] V --- G["seat gate"]How it works
Section titled “How it works”- Shared memory. Every api task talks to the same Valkey node, so a session made by one task works on the next.
- Allowed.
redis-sgallows TCP 6379 only fromapi-sg. - Password and TLS. Every connection must use TLS (the
sinrediss://) and send the auth token. Both come in theREDIS_URLsecret. - Data can expire or be replaced. Sessions expire after 7 days; cached lists and rate buckets sooner. Seat state is advisory and rebuilt from Postgres. Dev accepts this loss without backups.
In MiniTickets
Section titled “In MiniTickets”minitickets-dev-valkey is a replication group with one cache.t4g.micro node, Valkey 8.2,
port 6379, in the private subnets, with encryption in transit and at rest
(infra/src/data/cache.ts → createCache). One node means no replica and
no automatic failover.
Each layer handles its own Redis error differently:
| Use | When Valkey fails |
|---|---|
| Sessions | Requests with a session cookie fail; lost records require log-in |
| Events cache | Uses Postgres; each Redis operation has a 100 ms timeout |
| Rate limits | Fails closed: 503, so log-in floods stay bounded |
| Seat gate | Skipped: Postgres decides alone |
These are layer behaviors, not a whole-request fallback. Session lookup runs first. A full outage
can fail a request before it reaches the cache or gate
(apps/api/src/trpc/context.ts → createContext).
| From → to | What happens | What allows it |
|---|---|---|
| ElastiCache Valkey → Private subnetsonly when dataEnabled = true | the cache lives in the private subnets |
|
| ElastiCache Valkey → Cache security grouponly when dataEnabled = true | the cache uses the redis security group |
|
| API ECS service → ElastiCache Valkeyonly when computeEnabled = true | the Redis protocol over TLS (rediss://) on port 6379 |
|
| Sessions → ElastiCache Valkeyonly when dataEnabled = true | session:<hash> keys with a 7-day TTL |
|
| Events list cache → ElastiCache Valkeyonly when dataEnabled = true | the cached lists and the generation key |
|
| Rate limiter → ElastiCache Valkeyonly when dataEnabled = true | one token bucket per scope and caller |
|
| Inventory gate → ElastiCache Valkeyonly when dataEnabled = true | seat counters and leases per event |
|
See it in AWS
Section titled “See it in AWS”ElastiCache → Valkey caches → minitickets-dev-valkey: Primary endpoint, Encryption in transit:
Enabled, then the Events tab.
aws elasticache describe-replication-groups --replication-group-id minitickets-dev-valkey
Break it
Section titled “Break it”| Symptom | Cause | Where to look |
|---|---|---|
| Existing sessions stop working | Session lookup failed or records were lost | API log; ElastiCache → Events |
| Log-in without a session cookie returns 503 | redis-sg no longer allows api-sg | redis-sg → Inbound rules |
| Connection resets in the API log | URL uses redis://, TLS is required | The REDIS_URL secret format |
Say it in an interview
Section titled “Say it in an interview”Follow-ups
Section titled “Follow-ups”How would you make it highly available?
Two or more nodes in two availability zones with automaticFailoverEnabled and multiAzEnabled.
A replica takes over when the primary fails. Replicas add cost; dev keeps one node. Asynchronous
replication can still lose recent writes during failover.
See AWS replication behavior.
Why does the rate limiter fail closed, but the cache fails open?
The cache only saves work: without it Postgres answers, a bit slower. The limiter protects expensive password hashing; without it a flood could run unbounded, so refusing is safer.
Why Valkey and not Redis?
Valkey is an open-source fork of Redis. Our Redis commands and ioredis client work with it. That keeps our local Redis and AWS Valkey code the same; see Valkey’s compatibility guide.
Advanced: Why a replication group with one node
A node-based replication group gives us a primary now and optional replicas later. Our token
is a random 32-character string of letters and digits, safe inside the URL. Both encryption
settings are on from the start. AWS allows changing
in-transit encryption on Valkey 7.2 and later,
while at-rest encryption is set only at creation.
This corrects the older comment in infra/src/data/cache.ts.
Checkpoint
Section titled “Checkpoint”Answer these without scrolling up. If one feels hard, reread that section.
- Name the four things MiniTickets keeps in Valkey.
- Which rule allows the api to connect, on which port?
- What two things protect each connection?
- Why are there no backups?
- Which use fails closed, and why?
Redraw it from memory: the api tasks, Valkey, and its four uses
Try this: on the map, play the booking flow and open the failure branch of the sessions step
Read this book online: https://book.theversehub.in/