11.1 · The cache tiers
| Tier | Examples | Typical latency |
|---|---|---|
| Client | HTTP cache, SWR, IndexedDB | 0 ms |
| CDN / edge | Cloudflare, Fastly, CloudFront | 10–50 ms |
| API gateway | Kong, Apigee, Envoy filter | 5–20 ms |
| In-process | LRU, Caffeine, lru-cache | < 1 ms |
| Shared | Redis, Memcached, Valkey | ~1 ms LAN |
11.2 · Redis — beyond GET/SET
- Types: strings, hashes, lists, sets, sorted sets, streams, bitmaps, geo, JSON, search.
- Patterns: session store, leaderboard (ZSET), rate limit (INCR+EXPIRE), distributed lock (SETNX + Redlock with caveats), pub/sub, streams.
- Persistence: RDB snapshots vs AOF; hybrid for safety.
- HA: Sentinel + Cluster. Forks/alternatives: Valkey (Linux Foundation, post-Redis-license), Dragonfly, KeyDB.
11.3 · Cache pitfalls (and the fixes)
| Problem | Fix |
|---|---|
| Thundering herd on expiry | Jittered TTL; lock + refresh; stale-while-revalidate. |
| Cache penetration | Negative cache + bloom filter. |
| Cache stampede (cold) | Pre-warm; single-flight. |
| Inconsistency | Invalidate on write; CDC; short TTL. |
| Cache-only failure | Always fall back to source. |
11.4 · Queue vs stream
| Queue | Log / stream | |
|---|---|---|
| Consumed | Once, then deleted | Many consumers, independent offsets, replayable |
| Examples | SQS, RabbitMQ, Redis BLPOP | Kafka, Redpanda, Kinesis, NATS JetStream |
11.5 · Kafka / Redpanda
- Topics → partitions → replicas. Ordering per partition.
- Consumer groups with offset tracking; replay by resetting offsets.
- Connect (CDC / sinks), Streams / kSQL for in-flight processing.
- Redpanda: Kafka-API compatible, single binary, no ZK; lower op cost.
11.6 · NATS / JetStream
Tiny binary, sub-ms pub/sub; JetStream adds persistence + streams + KV + Object store. Sweet spot: microservice glue, IoT, edge.
11.7 · RabbitMQ
Classic AMQP broker. Exchanges (direct, fanout, topic, headers) + queues + DLX. Rich routing. RabbitMQ Streams adds Kafka-like log.
11.8 · Cloud-managed
| Service | What |
|---|---|
| AWS SQS / SNS | Queue + pub/sub; FIFO variants. |
| AWS EventBridge | Event bus with rules + schema registry. |
| GCP Pub/Sub | Global pub/sub with ordering keys. |
| Azure Service Bus / Event Hubs | AMQP + Kafka-compatible. |
| Cloudflare Queues | Edge queues bound to Workers. |
| Upstash / Momento | Serverless Redis / Kafka. |
11.9 · Durable execution
| Tool | Notes |
|---|---|
| Temporal | The flagship — write workflows in Go/Java/TS/Python/.NET; auto-resume after crashes. |
| Inngest | Serverless durable execution; great DX for TS/JS. |
| Trigger.dev | Background jobs + durable workflows. |
| Restate | OSS durable runtime with virtual objects. |
| Cadence | Uber's predecessor of Temporal. |
When to reach for it: any multi-step process that must complete eventually (onboarding, payments, sagas) but can take minutes / hours / days.
11.10 · Delivery patterns & semantics
| Pattern | Definition |
|---|---|
| At-most-once | Send and forget. Lossy. |
| At-least-once | Default; duplicates possible → consumers must be idempotent. |
| Exactly-once (effective) | Idempotent producers + transactions + consumer dedup. No magic. |
| Outbox | DB write + outbox row in one tx; relay publishes. |
| Inbox / dedup table | Consumer records processed IDs. |
| Saga | Long-running distributed transaction with compensations. |
| DLQ | Dead-letter queue for poison messages. |
| Backpressure | Bounded queues + signal upstream. |
11.11 · Self-check
Q1 · You need many services to consume the same events, each at their own pace, with the ability to replay history. Pick…
SQS
Kafka / log-style stream
Redis pub/sub
Direct HTTP fan-out