Skip to content
All writing ‹ Part 10 of 18 · A Cache Is a Chain, Not a Box
Engineering · 3 min read

How the Load Balancer Picks a Backend

How the origin load balancer picks a backend: path prefixes go to buckets, one header rule goes to a proxy, and one domain quietly splits into two routes.

The load balancer sends requests to different buckets by path prefix. One rule is an exception, because it reads a header.

In the last post I drew that a request reaches the load balancer (The Path of One Request). This post looks at how the load balancer picks the next stop.

origin(HTTP load balancer) exception:shared script paths bucket request withproxy header proxy(serverless) other paths,by folder prefix their ownbuckets nothing matches defaultbucket
Every rule routes by path to a bucket, except the one that reads the proxy header and sends the request to the proxy.
  • For most files, the path prefix sends the request straight to the bucket that holds the file.
  • The load balancer has one routing rule that reads a custom proxy header (x-use-proxy). The proxy itself does not read it. The CDN adds this header only to requests with an html, css, or js extension (Cache Headers: Who Sets, Who Reads).
  • Both the CDN and the load balancer look only at the file extension in the URL. They do not look at the MIME type of the response (Content-Type).
  • The proxy is a small service written in Go. It runs on a cloud serverless service, such as AWS Lambda, Cloud Run, or Azure Functions. It reads files from the bucket and rewrites some content.
  • The shared script rule comes before the header rule, so shared scripts do not pass through the proxy. This is the priority order from Load Balancer: One Entrance, Many Backends by Rule.

One Domain, Two Routes

Bucket route Proxy route
File types Images, video, shared JS html, css, js in the asset folder
Backend storage serverless compute
File source storage bucket Also a storage bucket, read through the proxy

At that time I saw this only as a routing setup. Later I learned that the cache behavior of the two routes is very different (A Bypass Header Works Only Where a Rule Reads It).

Both routes get files from the same bucket. What differs is the cache layer on the way.

Related: Load Balancer: One Entrance, Many Backends by Rule, Cache Headers: Who Sets, Who Reads, The Path of One Request, Two Cache Layers: What I Believed, A Bypass Header Works Only Where a Rule Reads It. Or go back to the series overview.

↑↓ navigate ↵ open esc close