Imagine an agency sharing a staging site with a client.
On Monday, the agency invites the client by email. On Friday, it removes them. The removal succeeds, but the client can still open the site.
Here is how that happens:
- The agency removes the client. The Durable Object holding the site's access list records the change immediately.
- The client's browser still has a signed Kinde token. The token remains valid until it expires. Kinde's default access token lifetime is 24 hours, and ending a session does not invalidate a token that has already been issued.
- A nearby data center has a cached copy of the access decision: this client may open the site. That copy is up to 30 seconds old.
- The client reloads the page. The gate finds the cached answer, trusts it, and grants access.
The token signature is valid. The cache is working as designed. The authorization decision is still wrong.
That is the problem I wanted to investigate with Wicket.
A signed token tells the gate who someone was when they authenticated. A cached access decision tells it what was true when that decision was last checked. Neither guarantees that the person is still authorized now.
Wicket is a small application that puts staging and preview sites behind an authentication gate. It runs on Cloudflare Workers and uses Kinde for authentication and billing. I built it to understand how authorization behaves when state is distributed across edge locations, and how long a revoked user can continue accessing a site.
The measurements in this article come from the deployed gate, tested against a real Kinde account from a laptop in Lagos. The Kinde outage test is simulated, which I explain in that section.
What Wicket does
Wicket puts a staging or preview site behind a sign-in page.
A Cloudflare Worker, which I call the gate, sits in front of the site. Visitors authenticate with an email address through Kinde. If the site owner has invited that email address, the gate forwards the request and attaches headers identifying the visitor. If the email is not on the access list, the gate refuses the request.
Site owners manage access from a dashboard or command-line tool. An invitation, which Wicket calls a grant, can also have an expiry time.
The owner's Kinde plan determines how many sites they can protect:
- Free: 1 site
- Pro: 10 sites
- Business: unlimited sites
There are four kinds of state behind this workflow. They do not all have the same consistency requirements, so they cannot all use the same storage strategy.
| State | Where it lives | How it changes |
|---|---|---|
| Kinde signing keys | Memory, then the data center cache, then Kinde | Rarely, when keys rotate |
| Site settings (address, open paths, mode) | Memory, then Workers KV | When the owner edits a site |
| Who may open a site | One Durable Object per site | On every invite, revoke, and expiry |
| Plan limit | Kinde, read when a site is created | When the customer changes plan |
A Cloudflare Durable Object is an object with globally unique identity and strongly consistent storage. The other stores in this design hold copies or cached versions of data.
That distinction matters. Site settings can tolerate some propagation delay. A revocation needs a much stronger guarantee.
Verify the token without calling Kinde
The visitor's browser holds a Kinde ID token in a cookie. The gate verifies its signature, issuer, audience, and expiry locally using signing keys already held in memory.
It also rejects tokens issued more than an hour ago, even if their expiry time is still in the future. The reason is straightforward: the token establishes the visitor's identity, but I want that proof to be recent.
Kinde publishes its signing keys at:
https://<your_subdomain>.kinde.com/.well-known/jwks
Its documentation provides the JWKS endpoint, but does not specify how long an application should cache the keys or exactly how it should handle rotation. Those are implementation decisions I had to make.
Wicket uses three rules:
- It refreshes the signing keys when the cached copy is older than 300 seconds.
- If a token contains an unfamiliar key ID, the gate makes one new JWKS request. It limits these requests to one every 10 seconds, so an unknown or forged key ID cannot force a call to Kinde on every request.
- If Kinde is unreachable, the gate continues using its existing keys for up to 24 hours.
There is also an important distinction between two failure states.
If the gate has no signing keys and cannot reach Kinde, it returns 503, not 401. A 401 tells the visitor their token is invalid and they should sign in again. But if the gate simply cannot obtain the keys needed to verify that token, it does not know whether the token is valid. Returning 503 represents that uncertainty more accurately.
Put access decisions somewhere strongly consistent
The most important question Wicket asks is:
May this email address open this site?
That answer needs to reflect invitations, removals, and grant expirations as quickly as possible. I store it in a Durable Object assigned to each site.
The gate asks the Durable Object for the decision. Memory and the data center cache sit in front of it to reduce the number of calls.
Workers KV is not suitable as the source of truth for this particular decision. Cloudflare documents KV as eventually consistent, with changes potentially taking 60 seconds or more to appear in other locations.
That delay is acceptable for site settings that rarely change. It is not acceptable for a revocation if the expectation is that removing someone should immediately stop access.
The cache layers still introduce a consistency problem, though. Each layer needs to know when the underlying answer was actually produced.
Wicket stores the timestamp returned by the Durable Object alongside the decision. It does not replace that timestamp with the time a cache entry was created.
This is easy to overlook.
Suppose a cache contains an authorization decision that is 20 seconds old. A Worker copies that answer into memory. If the Worker timestamps the memory entry with the current time, it now appears to be fresh for another five seconds. The memory layer might then refill from the data center cache, making the same old decision appear even newer.
The result is that copies can keep extending the life of an authorization decision without ever checking the source again.
By preserving the original timestamp, Wicket prevents that. An answer remains as old as the Durable Object's original decision, regardless of how many cache layers it passes through.
For a fast site, the cache windows are:
- Worker memory: 5 seconds.
- Data center cache: 30 seconds.
- Negative decisions: 2 seconds in both layers.
- Expiring grants: access stops at the grant's expiry time, even if a cached answer would otherwise remain valid.
Negative decisions have a shorter lifetime because the consequences are different. A stale yes can let a removed person in. A stale no can temporarily keep a newly invited person out.
A strict site skips both cache layers. Every request goes directly to the Durable Object.
How much does each tier cost?
I tested three sites on the deployed gate.
The first was a fast site receiving requests back to back. The second was another fast site, but it received one request every seven seconds. That interval is longer than the five-second memory window and shorter than the 30-second data center cache window. The third was a strict site receiving requests back to back.
For each request, the gate recorded which tier supplied the authorization decision and how long the request took from the laptop's perspective.
The network connection from Lagos accounted for roughly 200 ms before the gate did any work. A health page that skipped authorization entirely had a median response time of 200 ms.
Inside the gate, the median times were:
| Tier | Median time |
|---|---|
| Worker memory | 0 ms |
| Data center cache | 5 ms |
| Durable Object | 8 ms |
Two findings stood out.
First, the data center cache worked on a workers.dev address. It served 134 authorization decisions during the run.
Second, the cache was not faster at the tail. Its 95th percentile was 612 ms, compared with 235 ms for the Durable Object. In these runs, a cache hit avoided a Durable Object call but did not produce a better tail latency.
Memory was the only tier that was faster across every row. It is also the tier that disappears when a Worker instance is replaced.
This changed how I thought about the two site modes. The median latency difference between fast and strict was only 8 ms. The more important difference was how long a revoked user could continue getting access.
How long does a revocation take?
I wanted to measure that difference directly.
For each round, the test:
- Grants an email address access to a site.
- Makes four requests to confirm that the gate allows access.
- Revokes the grant.
- Sends another request every 100 ms until the gate refuses access.
- Measures the time between the revocation call returning and the first refusal.
I ran eight rounds against a strict site and eight against a fast site.
The results were clear.
The strict site refused the first request after the revocation. Its median wait was 0.21 seconds, and its longest wait was 0.24 seconds. That time represents one round trip.
The fast site took longer. Its median wait was 29.35 seconds, with the longest round taking 29.64 seconds. In every round, the last allowed decision came from the data center cache.
The 30-second cache window accounted for the entire delay. None of the runs exceeded it.
Cloudflare's Cache API documentation helps explain why Wicket cannot simply delete every cached copy after a revocation. Cache API entries are not replicated across data centers, and cache.delete only purges the cache in the data center where the Worker runs. A revocation in one location cannot directly remove copies held elsewhere.
That makes the cache window an explicit part of the product's authorization guarantee.
A fast site promises that a revocation will take effect within 30 seconds. A strict site promises that the next request will check the Durable Object directly.
The owner chooses the mode for each site. New sites use fast mode by default, while the command-line tool accepts --strict.
For sites where removing someone's access must take effect immediately, I would choose strict mode. Based on these measurements, the median cost was 8 ms.
What happens when Kinde is unreachable?
Kinde is needed during a request for one specific operation: retrieving the signing keys used to verify the visitor's token.
Wicket caches those keys for 300 seconds. Once that period passes, the gate attempts to refresh them. If Kinde is unavailable, the gate has to decide whether to keep trusting the existing keys or refuse requests.
Wicket uses both behaviours, depending on how old the keys are.
It continues using the cached keys up to a configured stale limit. After that, it returns 503. The default stale limit is 24 hours.
Owners can also designate paths as open. A health-check endpoint, for example, can skip authentication entirely, so a Kinde outage does not take that endpoint offline. Other paths fail closed once the signing keys exceed the allowed age.
I tested this behaviour on the deployed gate using a request header that makes the gate behave as though Kinde is unreachable for that request. The header can only simulate a failure; it cannot grant access. At the beginning of the test, the cached keys were seven seconds old, and I configured the stale limit to 60 seconds.
For the first 293 seconds, the gate continued returning 200 responses using keys from memory or the shared cache.
At 293 seconds, the cached copy became due for refresh. The gate then continued using the old keys for another 60 seconds.
The last 200 response arrived at 352 seconds. The first 503 arrived at 358 seconds. Requests were sent roughly every 5.5 seconds, so the refusal happened within one polling interval of the expected 353-second mark.
There was one detail I got wrong in my first attempt.
I initially treated the 60-second stale limit as though it started when the keys were first cached. But the gate does not check that limit while the copy is still within its 300-second refresh interval. It uses the existing copy without attempting a refresh.
The actual rule is therefore:
maximum key age = refresh interval + stale limit
With a 300-second refresh interval and a 60-second stale limit, the gate can use the keys for up to 360 seconds.
That distinction matters when configuring an outage policy. The stale limit does not represent the total age of the keys. It represents how long the gate will continue using them after a refresh becomes due.
Pass the visitor's identity to the protected site
Once the gate authorizes a visitor, the protected site needs a reliable way to identify them.
Wicket adds four headers to the forwarded request:
- The site identifier.
- The visitor's email address.
- A timestamp.
- A signature.
The signature uses HMAC-SHA256 and a secret shared between the gate and the protected site.
The protected site verifies the signature and rejects requests with timestamps more than 60 seconds old. Before forwarding the request, the gate also removes any incoming x-wicket- headers. That prevents a visitor from supplying their own identity headers and pretending to be someone else.
The protected site never receives the Kinde token and does not need to call Kinde. It only needs to verify the four headers using the shared secret.
Enforce plan limits where the count lives
Wicket also needs to enforce the number of sites an organization can protect.
It reads the protected_sites entitlement from Kinde's Management API when a site is created. The organization's Durable Object caches the plan limit for 30 seconds.
Kinde represents an unlimited feature with the value 2147483647. Wicket treats that value as unlimited rather than displaying it as a literal site allowance.
The important part is where the count and write happen.
Both operations run inside the same Durable Object, with no network call between checking the current count and creating the site. This means two simultaneous create requests cannot both pass a limit of one. The Durable Object processes them sequentially.
I ran into an unexpected issue while testing the plan limits.
After adding the protected_sites feature to the Pro plan, an organization that was already subscribed to Pro still reported zero of zero sites.
The reason was Kinde's plan versioning behaviour. When a plan is edited and published, existing subscribers remain on the version they originally joined. The updated entitlement applies to new subscribers.
To test the new limit, I had to move the organization off the plan and then subscribe it again. After that, Wicket reported zero of ten sites.
This is worth remembering when changing billing entitlements. Updating a plan does not necessarily update the entitlements of customers already subscribed to it.
Limits of these measurements
There are a few things to keep in mind when interpreting the results.
- All timings came from one laptop in Lagos. The network round trip was roughly 200 ms before the gate did any work. That variation is larger than the difference between the authorization tiers. I did not choose where Cloudflare placed the Durable Object, so these results do not establish how that tier performs from other locations.
- Each revocation result represents eight rounds. The fast-site measurements ranged from 29.17 to 29.64 seconds. That supports the 30-second cache window, but it does not tell us how the system behaves across many sites under load.
- The Kinde outage was simulated. A request header made the gate behave as though Kinde were unavailable. The key-rotation behaviour was tested with a fake Kinde in unit tests, not through an actual key rotation on a live tenant.
- Pausing a site has different consistency characteristics. Site settings are stored in Workers KV, so a pause can take the 60 seconds or more that Cloudflare documents for KV propagation. I measured revocations, which use Durable Objects. I did not measure site-pause propagation.
These measurements are useful for understanding the implementation and its trade-offs. They are not a global performance benchmark.
What I learned
An edge cache introduces multiple copies of the same authorization decision. Each copy needs a clear rule for how old it can be, and those rules need to survive when data moves between cache layers.
Three principles guided the implementation:
- Preserve the source timestamp. A cache refill must not make an old authorization decision look new.
- Set an explicit freshness window. That window determines how long a revoked user might retain access, so it is part of the product's security promise.
-
Refuse requests when the decision is too old. Returning
503when the gate cannot establish trust is safer than returning200based on an expired copy.
The most important design decision is the freshness window. It determines the maximum period during which a stale authorization decision can grant access.
For Wicket, that means a site owner has to choose between a 30-second revocation window and a direct Durable Object check on every request. The measured median difference was 8 ms, which makes strict mode a reasonable choice for sites where revocation speed matters more than avoiding that extra lookup.
Run it yourself
The source code is available in the Wicket repository.
You need a Cloudflare account and a Kinde account with billing enabled. Wicket is self-hosted: deploy the gate once, then manage protected sites through the command-line tool.
From the project directory:
npm install
cp .dev.vars.example .dev.vars
Add your Kinde machine-to-machine credentials, organization-to-customer mapping, and signing secret to .dev.vars.
Then run the tests and deploy:
npm test
npm run deploy
Before deployment, configure KINDE_DOMAIN and KINDE_CLIENT_ID in wrangler.toml, and add your organizations to public/config.js.
In Kinde, create a numeric feature with the code protected_sites on your plans. Add the gate's /_wicket/callback and /app URLs as callback URLs.
Upload the four required secrets using npx wrangler secret put, once for each:
KINDE_M2M_CLIENT_IDKINDE_M2M_CLIENT_SECRETCUSTOMERS_JSONSIGNING_SECRET
Sign in through the command-line tool and protect a site:
npx wicket-gate login org_xxxx --url https://your-gate.workers.dev
npx wicket-gate protect https://your-staging-site.example --name preview
The repository includes scripts for repeating the measurements. Each script needs room for two sites because it creates and removes its own test sites.
| Script | What it measures |
|---|---|
node scripts/tiers.mjs |
Round-trip latency and time spent in each authorization tier. Add --long for a longer run. |
node scripts/revoke.mjs 8 |
Eight revocation rounds against fast and strict sites. |
node scripts/kinde-down.mjs 60 |
Simulated Kinde outage with a 60-second stale limit. |
node scripts/local-e2e.mjs |
End-to-end gate checks against a fake Kinde instance on your computer. |
The steps for the local end-to-end test are documented at the top of its script.
FAQ
Why not put the access list in the token?
A token is signed when the visitor authenticates and remains valid until it expires. Kinde's default access token lifetime is 24 hours, and ending a session does not shorten an already-issued token's lifetime. An access list inside the token would become stale in exactly the same way.
Why not delete the cached copy after revoking someone?
Cloudflare's cache.delete only purges the cache in the data center where the Worker runs. Other data centers can still hold their own copies. The cache window provides the bound on how long those copies can be trusted.
Why does a negative decision expire after two seconds while a positive decision expires after 30?
A stale positive decision can let someone who has been removed continue accessing a site. A stale negative decision can temporarily prevent someone who has just been invited from getting in. The second mistake is less costly, so Wicket expires negative decisions sooner.
Why use a Durable Object instead of Workers KV for the access list?
Workers KV is eventually consistent, and Cloudflare documents that updates can take 60 seconds or more to reach other locations. A Durable Object provides strongly consistent storage for the access decision.
What happens if the gate cannot reach Kinde?
It continues using its cached signing keys. Once the keys are older than the refresh interval plus the configured stale limit, the gate returns 503. Open paths continue working because they skip authentication.
Does a signed token prove that someone still has access?
No. It proves the visitor's identity at the time the token was issued. Wicket checks current authorization separately, using the freshest access decision that is still inside its configured window.
Why does the stale limit start when a refresh is due?
The gate uses a cached copy without checking the stale limit while it is still inside the normal refresh interval. The stale limit only applies after that interval has elapsed.





Top comments (0)