AlgoViz

AWS Cloud Map

easy 26 min

AWS Cloud Map is a managed registry: services and other cloud resources are registered under a name with attributes, and callers find them through an API or through DNS.

See it run

Watch entries join, be found by API and by DNS, turn unhealthy, and be polled without passing the limit.

Operations

A task joins

ECS starts orders t-2 and registers it.

Step 1 of 4

One entry

web taskcallerCloud MapregistryRoute 53private zoneECSschedulerorders t-1healthyorders t-2not started

Answer for orders

t-1 10.0.1.7

Only t-1 is listed.

Step 1: One entry

task = start("orders", ip="10.0.2.4")register("orders", id="t-2", ip=task.ip)   # ECS does thisroute53.add_record("orders.shop.local", task.ip)wait_for(task.container_check)report("t-2", "HEALTHY")
Time
about 5 s
What you need
a service registry

Let the platform register, because it also cleans up after a crash.

In the real world

The same aws cloud map doing real jobs. Pick one and step through it.

All reports turn bad although the tasks are fine.

Step 1 of 3

Bad reports

web taskcallerCloud MapregistryRoute 53private zoneECSschedulerorders t-1really fineorders t-2really fine

A faulty checker reports both tasks as UNHEALTHY.

Step 1: Bad reports

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Reading the list in every request

    major

    Each user request becomes an API call, and the account limit is shared by everyone.

    Wrong
    def handle(req):    ip = discover("orders")[0]
    Right
    # one background loop per processinstances = keep_fresh("orders", every=30)def handle(req):    ip = random.choice(instances.current)
  • Long TTL with quick deployments

    major

    Callers keep dead addresses for the whole TTL.

    Wrong
    DnsRecords=[{Type=A,TTL=300}]
    Right
    DnsRecords=[{Type=A,TTL=10}]   # and drain for 10 s
  • Everyone may register

    critical

    An entry under payments receives payments traffic.

    Wrong
    "Action": "servicediscovery:*"
    Right
    "Action": "servicediscovery:DiscoverInstances"# register rights only for the platform role
  • First entry always

    major

    All callers hit the same copy.

    Wrong
    target = found["Instances"][0]
    Right
    target = random.choice(found["Instances"])

Interview tips

  • How to explain it

    • A managed list with attributes.
    • API or DNS to read it.
    • Callers connect directly.
  • Memory trick

    • Labels on pegs.
    • API fresh, DNS easy.
    • Thirty seconds to unhealthy.
  • Reach for it when

    • ECS services call each other.
    • Names for queues and tables.
    • Attributes choose the target.
  • Be careful with

    • Cached DNS answers.
    • The API limit.
    • Rights to register.