ステートレスサービスはリクエスト間でクライアント状態を保存しません(各リクエストは独立),一方ステートフルサービスは状態を維持します。ステートレス性はスケーラビリティにとって重要です — ステートレスサービスは水平スケーリングが非常に容易です。
ステートレス vs ステートフル
STATELESS → the service keeps NO client state between requests:
→ each request contains all needed info; any server can handle any request
→ state lives ELSEWHERE (database, cache, client, token) if needed
STATEFUL → the service MAINTAINS state across requests:
→ a specific server holds a client's state (session in memory, etc.)
→ requests must go to the SAME server (or state must be shared/synchronized)
ステートレス性がスケーラビリティに役立つ理由
STATELESS services scale horizontally EASILY:
→ any server handles any request → load balancing is simple (any server works)
→ add/remove servers freely; a failed server doesn't lose state → resilient
→ no sticky sessions or state synchronization needed
STATEFUL services are HARDER to scale:
→ requests tied to specific servers (sticky sessions); a server failure loses its state;
scaling needs state sharing/replication → complexity
→ PREFER STATELESS services for scalability (a key design principle).
