Skip to content

TB-005Bulletin

Why we rotate session tokens every 60 seconds

The token lifetime is the longest a revoked session can keep working. We wrote down the options between five seconds and an hour, and picked one.

Priya RamanStaff engineer, sessions, Bengaluru

Title
Technical bulletin
Doc. no.
LM-09 / TB-005
Subject
Infrastructure
Issued
27 Oct 2026
Reading
4 min

Every session design is a trade between two costs. A signed token can be checked anywhere without a network call, but it stays valid until it expires, whatever happens to the account. A session ID looked up in a database can be revoked at once, but every request pays for the lookup. We use both, and the number that connects them is 60 seconds. This is how we arrived at it.

1.0Two objects, two lifetimes

A session is a row in our database: user, device, creation time, last activity, status. It lives for seven days by default and can be ended by the user, by your code or by us. A session token is a JWT signed with ES256 that says “this session was alive a moment ago”. It carries the user ID, the session ID, the active organization and an expiry 60 seconds after issue.

Your backend only ever sees the token. It verifies the signature against public keys it already holds, checks exp, and moves on. No request leaves your infrastructure. The browser, meanwhile, trades the session for a fresh token shortly before the old one runs out.

Browser
Your server
Latch
request + token
verify signature, exp
refresh at 50 s
is the session alive?
new token, 60 s
Fig. 1.1One minute in the life of a session. Steps 1 and 2 repeat for every request; 3 to 5 happen once.

Request The 60-second token travels in a cookie on your own domain.

Local check Public keys are cached in memory. No network call, well under a millisecond.

Refresh Sent with the HttpOnly session cookie, which your JavaScript cannot read.

Session check The only database read in the loop: status, expiry and device.

Rotation If the session was revoked, this is a 401 instead and the tab signs out.

2.0Why 60, and not 5 or 3,600

The token lifetime is the longest a revoked session can keep working. That is the whole meaning of the number. Shorten it and revocation gets faster while refresh traffic grows; lengthen it and the reverse happens. We wrote the options down:

Per active tab. Refresh runs at five sixths of the lifetime.
Token lifetimeWorst-case revocationRefreshes per hourVerdict
5 s5 s864A lookup per request, with extra steps
60 s60 s72What we ship
5 min5 min14A stolen laptop stays signed in through a meeting
1 h1 h1Revocation in name only

At 72 refreshes an hour, a person who keeps a tab open for a working day makes fewer than 600 small requests. Each one goes to the nearest of 310 locations and the median round trip is 38 ms. Below a minute the curve turns against you quickly: at 5 seconds you have rebuilt per-request lookups and added clock-skew problems. Above a few minutes, “sign out everywhere” stops meaning what the button says.

Sixty seconds also matches how people describe the incident. “I revoked it and it was gone within a minute” is a sentence a security reviewer accepts. “Within the hour” is not.

3.0The parts that make it hold

  • Only visible tabs refresh. A background tab stops, and refreshes once when it comes back, before its first request. Forty open tabs cost the same as one.
  • Tabs take turns. Refresh runs under a Web Lock, and the new token is shared over a BroadcastChannel, so several tabs of the same app produce one refresh, not a burst.
  • Five seconds of leeway. Verification accepts a token up to 5 s past exp to absorb clock drift between machines. Not more: leeway is added directly to your revocation delay.
  • Keys rotate separately. Signing keys are published as a JWKS and identified by kid. SDKs cache the set and refetch when they meet an unknown kid, so key rotation needs no deploy.
middleware.ts
import { NextResponse, type NextRequest } from "next/server";import { verifyToken } from "@latch/nextjs/server";export async function middleware(request: NextRequest) {  const token = request.cookies.get("__latch_token")?.value;  // Local: signature, exp and audience. No network call.  const session = await verifyToken(token, { leeway: 5 });  if (!session) {    return NextResponse.redirect(new URL("/login", request.url));  }  const headers = new Headers(request.headers);  headers.set("x-user-id", session.userId);  return NextResponse.next({ request: { headers } });}
Caution
Do not cache the result of a verification for longer than the token's own exp. A five-minute cache in front of verifyToken turns a 60-second token into a five-minute one, and nothing will warn you.

4.0When a minute is too long

Some actions should not run on a token that is up to a minute old: changing the payout account, exporting every customer, deleting the organization. For those, ask for a live check. auth({ fresh: true }) makes one call to Latch, confirms the session row and returns in about the same 38 ms. Use it on the handful of routes where it matters and nowhere else.

Note
Mobile apps follow the same loop. @latch/expo refreshes when the app returns to the foreground and before any request made with a token that has under ten seconds left.

5.0What revocation looks like

  1. Someone ends the session

    The user from their device list, your code through the API, or an admin from the dashboard.

  2. The row is marked revoked

    From this moment no refresh for that session can succeed.

  3. The current token runs out

    At most 60 seconds later, plus 5 of leeway. Requests in that window still pass local checks.

  4. The next refresh returns 401

    The SDK clears its state and your app renders signed out. Other devices are untouched.

The design is not novel, and that is deliberate. Short-lived signed tokens over a revocable server-side session is the arrangement most careful teams converge on. What we add is the plumbing that makes it boring: the visibility handling, the tab coordination, the key rotation, and a default that is short enough to defend. You can change the lifetime per application between 30 seconds and 5 minutes. Almost nobody does.

38 ms

Median refresh

72/h

Refreshes per active tab

100%

Revocations applied in under 65 s

Fig. 5.1 — Sessions on Latch, 30 days to 20 October 2026.

6.0Get started

Read enough. Try the part.

Everything in these bulletins is switched on in the free plan: passkeys, 60-second tokens, organizations and roles, for your first 10,000 monthly active users.

npm install @latch/nextjs

Included on Free

Monthly active users
10,000
Passkeys, codes, links
Included
Social providers
3
Organizations
5 members each
Card required
No