Design a self-healing stateful service on EC2, such as a leader-based cluster, with EBS volumes.
AdvancedScenarioEC2, Auto Scaling and Load Balancing
Answer
Situation read → EBS is AZ-bound, so replacement logic must re-attach or rebuild in the same AZ.
What I'd do →
- One ASG per AZ with min and max 1, or lifecycle hooks that attach the volume
- Tag volumes and attach with a user data script using the instance's AZ
- Prefer replicated data (rebuild from peers) over reattachment
- Use EBS snapshots through Data Lifecycle Manager
- Alarm on replication lag
Why → Rebuild-from-peer avoids long reattach waits and corruption risk from forced detach.
Interview tip → If possible, push state to a managed service.