State Management

Overview

State management defines where application state lives, how it changes, and how consistency is preserved across distributed components.

State Categories

flowchart TD A[Client Request] --> B[API Service] B --> C[(Primary Store)] B --> D[(Cache Store)] C --> E[Event Stream] E --> F[(Read Model)]

Practical Example

A shopping application keeps cart session state in Redis and order state in PostgreSQL.

cartState: store: redis ttlSeconds: 1800 orderState: store: postgresql consistency: strong

This split keeps carts responsive while preserving transactional correctness for payments and orders.

Design Techniques

Common Pitfalls

Key Takeaways