概念
Microservices and stateless design
Small services that each do one job, own their data and scale alone, kept stateless so any copy can serve any request.
このレッスンはまだ翻訳されていないため、英語で表示しています。
Where state lives
- Stateless
- Outside: cache, database, S3
- Stateful
- On the server itself
Scale out
- Stateless
- Easy: add copies
- Stateful
- Hard: data must move
A server fails
- Stateless
- Replace it, nothing lost
- Stateful
- Data on it is lost
Typical example
- Stateless
- Web or API tier
- Stateful
- Database, file server
| Compare | Stateless | Stateful |
|---|---|---|
| Where state lives | Outside: cache, database, S3 | On the server itself |
| Scale out | Easy: add copies | Hard: data must move |
| A server fails | Replace it, nothing lost | Data on it is lost |
| Typical example | Web or API tier | Database, file server |
1 / 2
Where state lives
- Stateless
- Outside: cache, database, S3
- Stateful
- On the server itself
Scale out
- Stateless
- Easy: add copies
- Stateful
- Hard: data must move
A server fails
- Stateless
- Replace it, nothing lost
- Stateful
- Data on it is lost
| Compare | Stateless | Stateful |
|---|---|---|
| Where state lives | Outside: cache, database, S3 | On the server itself |
| Scale out | Easy: add copies | Hard: data must move |
| A server fails | Replace it, nothing lost | Data on it is lost |
2 / 2
Typical example
- Stateless
- Web or API tier
- Stateful
- Database, file server
| Compare | Stateless | Stateful |
|---|---|---|
| Typical example | Web or API tier | Database, file server |
概要
A monolith is one program that holds every feature. You deploy, scale and fix it as one unit. A microservices design splits it into small services, each with one job, such as orders, payments or search. Each service has its own code, its own release cycle and its own data store. Services talk through APIs or messages.
The main benefit is that each service scales and fails on its own. A busy search service can run 40 copies while the payment service runs 3. A bug in one service does not take the others down. The cost is more moving parts: more network calls, and more to monitor.
概要
A stateless service keeps nothing about a user between requests. Any copy can answer any request, so a load balancer can send traffic anywhere and Auto Scaling can add or remove copies freely. State moves out of the server: sessions to Amazon ElastiCache or Amazon DynamoDB, files to Amazon S3 or Amazon EFS, data to a database. A stateful service keeps data on its own server. It is harder to scale out, and a failure loses that data.
覚えること
- Stateless: no user data kept on the server between requests.
- Move session state to ElastiCache or DynamoDB, and files to S3 or EFS.
- One service, one data store: services never read each other’s tables.
- Scale and deploy each service on its own.
覚えること
- Break a monolith up step by step: carve out one service at a time behind the same front door.
- Services talk by API call (synchronous) or by queue and event (asynchronous).
試験では
- “Any instance can fail without logging users out” points to storing sessions in ElastiCache or DynamoDB, not on the instance.
- “Scale the checkout feature without scaling the whole application” points to splitting it into its own microservice.
- “Sticky sessions” in a question often hint that the design is stateful and should change.
混同しやすいもの
- Multi-tier architecturesWeb, application and data tiers, each in its own subnets, scaled on its own and reachable only from the tier above.
- Horizontal vs vertical scalingScale out for capacity and availability, scale up for a quick fix, and scale each tier on its own metric.
- Event-driven and loose coupling patternsParts that talk through queues, topics and events, so a slow or failed part does not stop the others.
このタスクの内容 · 2.1
- Microservices and stateless design
- Multi-tier architectures
- Event-driven and loose coupling patterns
- Serverless application patterns
- AWS Amplify and AWS Device Farm
- Horizontal vs vertical scaling
- Caching strategies
Load Balancing
API Gateway
- When and how to containerize
SQS
SNS
EventBridge
Step Functions
MQ
Secrets Manager
- Choosing purpose-built services
- Choosing object, file or block
Lambda
- Read replicas
ElastiCache
CloudFront
Global Accelerator
Transfer Family
S3
EFS
EBS
Fargate
ECS
EKS