
Replacing an application container should be routine. A new image starts, readiness checks pass, traffic moves, and users continue working.
Real applications also have cached documents, open browser tabs, asynchronous requests, and authentication state that must remain consistent throughout the transition. A deployment can bring those moving parts into contact in unexpected ways.
An older homepage, a failed API request, and an interface that suddenly shows a login button can look like one problem. Each calls for a different investigation.
At ZyVOP, reviewing deployment behavior led us to examine the boundaries between build freshness, cached content, and session continuity. The examples here are generalized so the engineering lessons remain useful without exposing private operational details.
Separate page freshness from authentication
Start by asking two questions:
Which version of the application or document reached the browser?
Does the backend still recognize the user's session?
An old document can display an outdated interface while the session remains valid. A current document can encounter a temporary authentication-service failure. A session can also legitimately expire while every cache is behaving correctly.
These are distinct states, and the application should give them distinct meanings.
Layer | Responsibility | What to investigate |
|---|---|---|
Image construction | Produce application artifacts | Source inputs, build arguments, and cache invalidation |
Application runtime | Serve the deployed version | Image identity, readiness, and traffic handoff |
CDN | Cache eligible responses | Cache policy, response age, and document freshness |
Browser | Run the interface and retain browser state | Loaded assets, cookies, and pending requests |
Authentication service | Validate sessions | Credentials, expiry, revocation, and recovery outcomes |
A CDN purge removes cached content at the edge. It does not perform an application logout or delete cookies already stored in a user's browser. Replacing an application container likewise should not end sessions when the authentication dependencies and configuration remain consistent.
That gives the investigation a useful starting point: identify the state transition that actually happened before choosing a fix.
Verify the running image before changing cache settings
When a deployment appears old, verify that the expected image was built, published, pulled, and started.
A successful build command alone does not prove that traffic reaches the new image. Compare the image selected for deployment with the identity of the running replacement. Then verify that the traffic handoff completed.
For builds, distinguish dependency reuse from application-output reuse. Reusing a dependency layer can save time while still allowing current source files and configuration to produce fresh application output.
Build inputs can also exist outside source files. For example, static generation may fetch content, and a build step may consume a mounted secret. Docker documents that secret contents themselves do not invalidate build cache, so workflows need an explicit strategy when those inputs affect output. Docker build cache invalidation
A reliable release process therefore answers both questions: did the build process evaluate the necessary inputs, and is the intended artifact actually serving requests?
Treat cached HTML and hashed assets as a release lifecycle
A fresh container can coexist with an older document in a CDN or an already-open browser tab.
That document may reference JavaScript and CSS from an earlier release. If the deployment removes those assets immediately, the browser can fail when it requests a file that the new origin no longer serves.
The public symptom might be broken navigation, a failed hydration step, or an authentication interface that never finishes initializing. None of those symptoms alone proves that the backend revoked a session.
Two release practices help:
Refresh changed documents after the replacement is healthy.
Keep previously referenced immutable assets available for an appropriate compatibility period.
The appropriate retention and cache policies depend on the application. A CDN cache entry should not be the only place an older asset remains available.
Cloudflare supports targeted URL purging, which can be useful for refreshing changed documents without indiscriminately discarding unrelated cached content. Cloudflare cache purging
When diagnosing freshness, inspect the relevant response headers and compare release identities through authorized diagnostic paths. Account for the application's own rendering or data cache as well as the CDN.
Understand the ambiguity created by a lost response
Authentication renewal often changes backend state before the browser receives confirmation.
Consider a session-renewal operation. The server validates the request and records a successful renewal. Before the browser receives the response, the connection is interrupted.
The server knows the operation completed. The browser knows only that it did not receive confirmation.
That ambiguity can occur during a deployment handoff, a network interruption, or an ordinary request timeout. It is a general distributed-systems problem: the absence of a response does not establish whether an operation committed.
sequenceDiagram
participant Browser
participant App as Application
participant State as Shared state
Browser->>App: Request session renewal
App->>State: Commit renewal outcome
State-->>App: Outcome recorded
App--xBrowser: Response lost in transit
Note over Browser,App: Client has not received confirmation
Browser->>App: Retry the same operation
App->>State: Validate bounded recovery
State-->>App: Recovery outcome
App-->>Browser: Return verified resultA safe recovery design must handle that uncertainty while continuing to reject expired credentials and unauthorized reuse. Refresh-token rotation and replay detection remain important security controls. RFC 9700, refresh-token protection
Represent temporary unavailability explicitly
The frontend needs to distinguish an ended session from an unavailable answer.
A useful model has three outcomes:
type SessionCheck =
| { status: 'authenticated' }
| { status: 'unauthenticated' }
| { status: 'unavailable' };An authenticated result confirms the session. An unauthenticated result confirms that the application considers it ended or invalid. An unavailable result means the client cannot establish the answer yet.
Timeouts, malformed gateway responses, and infrastructure failures should not automatically clear the user's last known state. Otherwise, a short outage becomes a visible logout even when the backend still recognizes the session.
Interpret responses according to the documented API contract. Some applications use HTTP authentication status codes for a definitive rejection; others return an application-level outcome. The client should recognize the contract deliberately rather than infer logout from every failed request.
A cached user profile can help preserve continuity in the interface while a check is unavailable. It remains a display aid: protected operations must still require valid authorization from the backend.
Make uncertain retries bounded and idempotent
Retrying a renewal request should not accidentally create several conflicting outcomes for the same operation.
An idempotent recovery path lets the backend recognize a retry and recover the previously committed result when the request remains eligible. The backend validates that eligibility using shared state and the application's security policy.
The public design requirements are straightforward:
Recovery has a bounded lifetime.
A retry must be associated with the operation being recovered.
Logout, expiry, and revocation continue to take precedence.
Recovery must not roll a client back to obsolete authentication state.
Unrelated or unauthorized reuse must continue to be rejected.
Recovery is an explicit policy choice with a security tradeoff. Its identifiers, validity rules, storage protections, and lifetime need review together. An idempotency mechanism does not replace authentication or provide cryptographic device binding by itself.
These controls also do not promise permanent sessions. A prolonged outage, browser suspension, unavailable state, or a completed revocation can still require the user to sign in again.
Keep shared decisions atomic
During a deployment, old and replacement application instances can overlap. They may receive requests relating to the same session.
A sequence of independent reads and writes can allow both instances to observe an eligible operation and produce different results. A process-local lock cannot coordinate separate containers.
Put the shared decision behind a consistency mechanism that covers all participating instances. Depending on the architecture, that might be a database transaction, an atomic conditional write, or a short Redis script.
Redis Lua scripts execute atomically with respect to other Redis activity. That can make them useful for a compact state transition involving multiple checks and updates. Redis scripting semantics
Keep the operation bounded and review failure behavior. Shared security state also needs a deliberate operational lifecycle; it should not be treated as disposable merely because the storage technology is also used for caching.
Coordinate retries without overwhelming recovery
Retry behavior should account for both the server's recovery budget and the browser's execution model.
Use bounded attempts with backoff, coalesce duplicate work within a tab, and coordinate across tabs where appropriate. Avoid allowing every failed request to launch an independent renewal loop.
Browser timers are not precise execution guarantees. Background tabs can be suspended, devices can sleep, and network connectivity can change. Recovery should tolerate those realities without assuming that a client-side timer proves a server-side request is still eligible.
For temporary unavailability, reconnect and focus events can provide opportunities to check again. Periodic recovery can also help an open page resume after an outage, provided attempts remain coordinated and stop after a confirmed outcome.
The interface should preserve useful context while waiting. It should also make it possible to distinguish an unavailable service from an application that has definitively requested a new login.
Prevent older asynchronous work from replacing newer state
A request can become obsolete even when it succeeds.
Suppose a session check starts, then the user explicitly signs in or signs out before that check finishes. Applying the older result afterward can overwrite a newer decision.
A generation counter is one way to protect the client state transition. Advance the counter when an explicit authentication change establishes newer state. Work captures the generation it belongs to and checks it again before its result is applied.
Here is a deliberately generic example:
async function applyIfCurrent<T>(
getVersion: () => number,
checkSession: () => Promise<T>,
applyResult: (result: T) => void,
): Promise<void> {
const startedAtVersion = getVersion();
const result = await checkSession();
if (startedAtVersion !== getVersion()) {
return;
}
applyResult(result);
}Check the boundary after asynchronous coordination as well as after the network operation. Releasing a lock or resolving an intermediate promise can create another handoff before a caller receives the result.
Cancel obsolete network work where possible. Cancellation can reduce interference, but it cannot undo an operation already committed by the server. Client-state guards and backend recovery therefore address different parts of the problem. AbortController behavior
Preserve the information needed to classify profile errors
A profile query can make an authentication decision indirectly. If it returns no user, application code may decide to clear the signed-in interface.
GraphQL complicates this because a response can contain both partial data and errors. Discarding the errors can make a temporary resolver failure look like an ordinary null result.
Apollo Client provides error policies that control how data and errors are exposed. Choose the policy that preserves the information required by the caller, then classify infrastructure and authentication failures deliberately. Apollo Client 3 error policies
A useful regression test sends a null profile alongside an infrastructure error through a real client. Verify that the application preserves the last known user instead of concluding that the session ended. Test a confirmed authentication failure separately.
This catches configuration mistakes that a pure helper test can miss. The helper may behave correctly while the query configuration removes the evidence it needs.
Test the boundaries between successful steps
The difficult cases often sit between operations that each appear correct in isolation.
We tested the recovery design at several levels:
Boundary | What the test should establish |
|---|---|
Renewal committed, response missing | An eligible retry can recover the intended outcome |
Application instance replaced | Recovery does not depend only on the old process's memory |
Concurrent attempts | Shared decisions remain consistent |
Logout or credential change | Recovery cannot override the security decision |
Expired or unrelated recovery | The backend rejects it |
Newer client state established | Older responses cannot replace it |
Profile query fails temporarily | Error handling does not manufacture a logout |
Browser reconnects or closes | Recovery resumes or cleans up appropriately |
Use signed credentials and the real authentication service in composed tests where practical. Exercise the actual shared-storage implementation as well as any local fallback. Test the client library's behavior when its error policy is part of the decision.
Our verification included frontend and backend suites, type checking, targeted lint, and an isolated shared-storage integration test. Some environment-dependent database checks were excluded from the broad run, so they should not be represented as completed coverage.
Passing these checks supports the tested behavior. It does not prove that every production failure mode has been eliminated or establish the cause of a particular user's report.
Roll out compatible changes and measure session outcomes
Coordinate backend and frontend changes so the server can understand a recovery mechanism before a client depends on it. Preserve the authentication configuration and state required for continuity across application replacements.
After rollout, correlate deployment events with aggregate session outcomes. Distinguish successful renewals, temporary failures, expected expiry, and security-driven rejection. Avoid recording raw credentials or unnecessary personal identifiers in diagnostics.
Investigate cache freshness separately. If a page looks old, inspect its release and cache evidence. If a session ends, inspect the authentication outcome. If a request is interrupted, establish whether the operation committed before deciding how to retry it.
Reliable deployments come from making those boundaries explicit. Fresh artifacts, compatible assets, clear authentication states, and bounded recovery each solve a different part of the user's experience—and together help users continue their work through routine releases.
Comments(0)
Join the discussion by logging into your account.
No comments yet. Be the first to comment!