AWS Cloud Map
easy 26 minAWS 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
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
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
majorEach user request becomes an API call, and the account limit is shared by everyone.
Wrongdef 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
majorCallers keep dead addresses for the whole TTL.
WrongDnsRecords=[{Type=A,TTL=300}]RightDnsRecords=[{Type=A,TTL=10}] # and drain for 10 sEveryone may register
criticalAn entry under payments receives payments traffic.
Wrong"Action": "servicediscovery:*"Right"Action": "servicediscovery:DiscoverInstances"# register rights only for the platform roleFirst entry always
majorAll callers hit the same copy.
Wrongtarget = found["Instances"][0]Righttarget = 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.