Advanced

Layers between the app and the client

The app is rarely alone. A proxy, a load balancer, and a CDN sit in front of it, and each one rewrites a header the app wrote.

What you will see

One line. The header is the claim both sides agree on.

About 1 min of reading

Try It

Order the timeouts

1

Write the layer timeouts

printf 'cdn 3000\nbalancer 8000\napp 5000\n' > /tmp/t.txt; sort -k2 -n /tmp/t.txt | head -1

Before you run it, say out loud what it will print. Then open the answer.

What it prints
cdn 3000. The smallest is the ceiling, and the ceiling is not the app's.
2

Write the order rule

printf 'rule=app-smaller-than-outside\n' > /tmp/r.txt; cat /tmp/r.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line. The app must be smaller, or the app is blamed for a timeout it did not cause.
3

Name the forwarded header

printf 'forwarded_proto=x-forwarded-proto\n' > /tmp/h.txt; cat /tmp/h.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line. The header is the claim both sides agree on.

Data Flow

A client to the app
1 The client sends a request
↓
2 Each layer rewrites what it owns
↓
3 The app reads the forwarded claims
↓
4 The timeouts are ordered and written
Why this works
Why the layers are drawn

The drawing names each layer and its timeout. A drawing with numbers is a drawing that can be argued with.

The symptom of a missing layer

A behaviour that works in a test and fails in place. The difference is a layer, and the layer is the cause.

Examples

The scheme may be rewritten

The proxy ends TLS and the app sees http. A redirect built from the app view is a redirect to the wrong host.

The forwarded headers are the fix

The proxy says what it removed. The app reads the claim, and the claim is a header both sides must agree on.

The layer count is a number

Each layer has its own timeout. The smallest timeout is the ceiling, and the ceiling is not the app's.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Running the server is a choice
Previous Lesson
Running the server is a choice
Next Lesson
Authentication in front of a Flask app
Authentication in front of a Flask app →