Skip to content
GenAI Learn/AI Architecture Patterns
Browsing as a guest. Sign in to save your progress and earn XP as you complete chapters.

Distributed AI Application Design

4 min readChapter 5 of 5

You'll learn to

  • -Explain why an AI application is split across machines and what each split costs
  • -Write down a contract for a network call: schema, timeout, retry rule and error shape
  • -Split a latency budget across hops and pass the remaining time along as a deadline
  • -Compute end-to-end availability from the availability of each hop

Tip: the highlighter is on - just select any text below to mark it. Use the highlighter button up top to change color or turn it off. Highlights are saved on this device only. Log in to save them to your account instead.

Sooner or later the whole application no longer fits on one machine, or should not. The language model needs a GPU and the search service needs memory and fast disks. The gateway needs to scale to thousands of connections and the guardrail needs to be owned by the safety team. So the application becomes several services that talk over a network. This chapter is about the new problems that arrive with that split.

An Analogy: A Parcel Through Depots

A parcel crosses five depots to reach you. Each depot promises a handling time. If one depot is slow, the later depots cannot make up the time unless they are told how much is left. And if each depot is open 99.9 percent of the time, the chance that all five are open is lower than any of them. The same two facts, time adds up and availability multiplies, govern a chain of AI services.

What You Gain and What You Pay

  • -Gain: each service scales on its own, runs on the right hardware, and can be owned, deployed and rolled back separately.
  • -Pay: every hop adds network time and a new way to fail, and a call can succeed on one side and look failed on the other.
  • -Pay: versions drift. A caller and a callee may be running different versions of the same contract for a while.
  • -Pay: debugging spans machines. You need traces that follow one request across every service.

Contracts for Network Calls

A call across the network needs more than the data shape. It needs a timeout, because waiting forever is the worst failure. It needs a retry rule that says which errors may be retried and how many times, and retries are safe only for idempotent calls. It needs an error shape the caller can act on, and a version, so old and new callers can coexist.

Now the numbers. The code below lists five hops with a made-up p95 latency and availability. It sums the latencies against a two second budget and multiplies the availabilities. Then it runs a day when the language model is slow, nearly twice its normal time, to show what passing a deadline along does.

Press Run: a latency budget, an availability product and a deadline that travels

The hop p95s sum to 1,780 ms inside a 2,000 ms budget. Adding p95s is a conservative planning rule, not an exact one, because the slow case rarely happens at every hop at once. The availabilities multiply to 99.202 percent, about 4,195 minutes down a year, even though no single hop is worse than 99.5 percent. On the slow day the model hop was given a timeout of 1,620 ms: the time left, minus what the later guardrail hop needs. It timed out, a fallback answer was used, and the request still finished in 2,000 ms.

Ways to Spend Fewer Hops and Fewer Nines

  • -Pass a deadline with every request, and give each hop the time left minus what the remaining hops need.
  • -Give every hop a fallback: a cached answer, a smaller model, or a partial result flagged as partial.
  • -Run independent calls in parallel, such as retrieval and a safety check on the question, so their times overlap.
  • -Merge two services that always change and fail together. Every hop you remove helps both the budget and the availability.

Before adding a service, write down its latency, its availability and its fallback next to the budget. If you cannot say what the system does when that service is down, it is not ready to be a hop. The gateway and disaster recovery chapters show the failover side of this.

Interview Signal is part of Pro

See a real weak answer next to a real strong one for this exact topic.

Quiz is part of Pro

Test what you just read with a short quiz, and bank the XP.

Discussion0

Join the Discussion

Sign in to leave comments, reply to others, or like insights.

Sign In to ScaleDojo

No comments yet. Be the first to start the thread!