ladderlore
  • S3 や IAM などのサービス名を入力してください。

概念

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.

このレッスンはまだ翻訳されていないため、英語で表示しています。

Every copy reads the session from a shared store, so the load balancer can use any of them.
  • 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
Make the tiers stateless and keep the state in services built for it.

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

2 / 2

  • Typical example

    Stateless
    Web or API tier
    Stateful
    Database, file server
Make the tiers stateless and keep the state in services built for it.

概要

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.