List watch and concurrency
List once, then follow changes
A controller often needs a local cache of objects. Start with a LIST of the chosen collection and retain the collection metadata.resourceVersion. Start a watch of that same collection using that value. A watch streams notifications of changes instead of repeatedly polling all objects. The token describes a server-defined position in resource history; portable clients treat it as opaque and do not increment it or interpret it as wall-clock time. An item version is not a substitute for the collection version. The following tokens and objects are synthetic.
{ "metadata": { "resourceVersion": "snapshot-A" }, "items": [ { "metadata": { "name": "catalog", "uid": "uid-a", "resourceVersion": "item-X" } } ]}Pagination and a consistent initial cache
Large collections can be requested in pages using limit and the server-issued continue token. Keep the same query parameters other than continue and accumulate the pages until the token is empty. A continued list can represent a consistent collection snapshot. If the token expires and the server returns 410, restart the list for a consistent result instead of merging new pages with an old partial cache. A server may offer a token for resuming at a newer snapshot, but that is not equivalent to the original snapshot. Do not invent continuation tokens.
GET /api/v1/namespaces/book-lab/pods?limit=2response: resourceVersion=snapshot-A, continue=page-BGET /api/v1/namespaces/book-lab/pods?limit=2&continue=page-Bresponse: resourceVersion=snapshot-A, continue=""Watch events, interruptions and stale history
ADDED and MODIFIED provide object state; DELETED removes the corresponding lifetime from the cache. BOOKMARK, when requested and supplied, advances the known progress without adding an object. It is not guaranteed at a fixed interval. An ordinary disconnect can be followed by a new watch from the last processed version. If the server can no longer supply that history, a 410 Gone response or an equivalent watch error requires a fresh list and cache replacement before watching again. An error is not an object update. Treat reconciling work as repeatable; do not assume one event equals one action.
LIST -> snapshot-AMODIFIED -> event-BBOOKMARK -> event-Cconnection lost -> reconnect from event-C410 Gone -> discard stale cache, relist, restart watchOptimistic concurrency and retry boundaries
A read-modify-write update can include the resourceVersion read from the object. If a competing update changed the version, the server can reject the stale write with 409 Conflict. Read the current object, recompute the intended change, and retry with a bounded policy; do not simply overwrite a newer object. This concurrency conflict differs from a server-side apply ownership conflict, which needs field-owner resolution. A 429 indicates throttling or overload; respect Retry-After when provided, use bounded exponential backoff with jitter, and avoid retry storms. API Priority and Fairness classifies and limits competing request flows; configuration and metrics require actual cluster evidence. Authentication/authorization failures need diagnosis, not infinite retries.
client A GET: version Xclient B updates: version Yclient A PUT with X: 409 Conflictclient A GET: version Y; recompute; retry with YPractice: recover the cache
Use watch-events.json and recovery-cases.json. Reconstruct the cache by UID, retain the last token, and decide how to respond to an expired watch or list continuation. Compare 409, 410, 429 and 403. The fixture models a narrow sequence of known responses; it is not an HTTP client or a Kubernetes watch implementation. Next, examine what happens to a write before and after it is accepted.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
List watch and concurrency — knowledge check
Interpret synthetic Kubernetes API evidence.
Which version starts a watch after an initial list?
A continued list expires with 410. How can you regain a consistent initial snapshot?
A BOOKMARK arrives. What should the cache do?
A read-modify-write receives 409 because the object changed. What next?
A server returns 429 with Retry-After. What is appropriate?