Video in progress

A request goes through a synchronous chain A → B → C → D. What problems does that have?

Latencies add up and availabilities multiply: if each is 99.9% available, the whole chain is about 99.6%. On top of that, a single slow or dead service stops the entire request.

📖 Answer

Simple math:

A: 20 ms, B: 50 ms, C: 80 ms, D: 40 ms  -> at least 190 ms + network
availability: 0.999^4 ≈ 0.996  -> ~3 hours of downtime a month (~43 minutes for a single service)

More problems:

  • mismatched timeouts: A waits 2 seconds, but B waits 5 seconds for C. A has already given up while B is still working and burning resources;
  • retries multiply: 3 attempts at each layer can bring up to 27 requests to D;
  • hard to debug: without tracing it's tough to find which step is slow.

What you can do:

  • run independent calls in parallel (CompletableFuture or virtual threads);
  • move the parts the user doesn't have to wait for to asynchronous;
  • keep frequently needed data as a copy in your own service (updated through events);
  • pass a shared "deadline" along the chain, so each next service doesn't wait longer than the time that's left.

If the chain length goes beyond 3-4, it's usually a sign the boundaries were drawn wrong.