1.1.5 Fault-Tolerant & Resilient Applications
Fault-Tolerant & Resilient Applications
Retry Logic
- Exponential backoff with jitter
- AWS SDK tự động retry với exponential backoff
- Configurable:
maxRetries, retryMode (standard, adaptive)
import boto3
from botocore.config import Config
config = Config(
retries={'max_attempts': 5, 'mode': 'adaptive'}
)
client = boto3.client('dynamodb', config=config)
Circuit Breaker Pattern
- Ngăn cascade failures
- States: Closed → Open → Half-Open
- Khi error rate cao → circuit opens → fail fast
Idempotency
- Đảm bảo xử lý nhiều lần cho cùng kết quả
- Dùng idempotency token/key
- Quan trọng cho Lambda retries
Error Handling Best Practices
- Try/catch cho AWS SDK calls
- Handle specific exceptions (
ThrottlingException, ServiceUnavailableException) - Dead-letter queues cho failed messages
- Fallback responses cho graceful degradation
Exam Tip: Khi đề bài nói “retry” → exponential backoff. Khi nói “prevent cascade failure” → circuit breaker. Khi nói “duplicate processing” → idempotency.