liveBook · Manning

Session affinity

As explained in Learn Docker in a Month of Lunches, Second Edition

A sticky session is session affinity that routes repeated requests from a client to the same service instance when possible.

Session affinity routes repeated requests from one client to the same service instance when possible. It helps older applications that are not stateless, while stateless applications generally benefit from routing requests to any available container. section 20.4

Traefik implements session affinity by:

  • Setting a cookie that identifies the container for the client. section 20.4
  • Reading that cookie on later requests and routing them to the same container. section 20.4
  • Keeping repeated calls together instead of distributing them across scaled containers. section 20.4

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains the cookie-based routing mechanism and demonstrates it with scaled containers, but does not detail service-label syntax.
Examples
Demonstrates a scaled who-am-I application, repeated curl requests, and a c.txt cookie jar.
What it assumes
Assumes Docker Compose, containers, curl, and basic load-balancing concepts.
What you can do after
Configure and verify sticky sessions in Traefik while comparing cookie-persisted routing with ordinary load balancing.
How it connects
Connects session affinity with load balancing, reverse proxies, stateless components, cookies, and container scaling.

Also explained in

Compare how 2 books explain session affinity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.