All posts
Developers·· 9 min read

API Key Rotation Without a Single Byte of Downtime

Rotating API keys shouldn't feel like defusing a bomb. Here's the exact dual-overlap pattern we ship in production — zero dropped requests, no 3 a.m. pages.

By AtlasForge Financial Editorial
API Key Rotation Without a Single Byte of Downtime

Most engineering teams treat API key rotation like a necessary evil — something you schedule for 2 a.m. on a Sunday, fingers crossed, Slack open, ready to roll back. That's not a secrets management strategy; that's superstition with a runbook attached.

At AtlasForge Financial, we rotate credentials on a 30-day cycle across every integration that touches the AtlasForge Financial API — payment processors, data aggregators, KYC vendors, internal microservices — and we have not had a single rotation-related outage since adopting the pattern described here. The approach is not novel in isolation, but the implementation details matter enormously. Let's walk through exactly how it works.

Why Rotation Fails in Practice

Before the solution, the diagnosis. Credential rotation outages almost always trace back to one of three root causes:

  1. Hard-coded keys in environment variables that require a process restart — and a restart window — to pick up new values.
  2. Single-key architecture where invalidating the old key before every consumer has rotated causes a gap of failed authentication.
  3. No observability on which services are still using which key version, so you can't tell when it's safe to retire the old credential.

The 2023 CircleCI breach — where threat actors exfiltrated customer secrets stored in a third-party analytics system — accelerated industry thinking on rotation cadence. The NIST SP 800-57 guidance, updated in 2024, now explicitly recommends automated rotation over manual procedures for any secret with a cryptoperiod exceeding 90 days. The CFPB's supervisory guidance on third-party risk echoes this for financial data APIs specifically: credential hygiene is increasingly treated as a compliance matter, not just an engineering preference.

The Dual-Key Overlap Window

The foundational pattern is simple to describe and surprisingly rare in the wild: never invalidate a key until you can prove nothing is using it.

Here's the canonical 60-second rotation sequence we use:

  1. Generate a new API key (Key B) via the issuing system's provisioning endpoint.
  2. Distribute Key B to all consumers — config service, secrets manager, environment — without touching Key A.
  3. Open an overlap window (we use 15 minutes for external vendors, 60 seconds for internal services) during which both Key A and Key B are simultaneously valid.
  4. Verify that all consumers have acknowledged and are actively using Key B by checking authentication logs for Key A call volume dropping to zero.
  5. Revoke Key A only after zero observed usage for a full TTL cycle.
  6. Alert if Key A sees any authenticated request after revocation — that's a consumer that missed the rotation.

The overlap window is the non-negotiable piece. Without it, you're relying on perfect coordination across every consumer simultaneously. With it, you're relying on eventual consistency — a much more achievable bar in distributed systems.

Choosing Your Overlap Duration

Overlap duration is a function of two variables: consumer latency to reload secrets and your threat model for key exposure.

  • Internal services using a push-based secrets manager (HashiCorp Vault, AWS Secrets Manager with Lambda rotation): 60–120 seconds is sufficient.
  • External partners pulling credentials from a shared config endpoint on a polling interval: set overlap to at least 2× the polling interval, plus a safety margin. If they poll every 5 minutes, use 12–15 minutes.
  • Any key that may have been compromised: revoke immediately, accept the incident, and let your runbook handle remediation. Overlap windows are not for emergency revocation — they're for planned rotation.

Secrets Distribution Without Process Restarts

The dual-key pattern only works if consumers can pick up new credentials without restarting. This rules out the classic process.env.API_KEY pattern in most runtimes.

We use a two-layer approach across our infrastructure:

Layer 1 — Secrets Manager with Dynamic Fetching. Every service that calls an external API does so through a thin credentials wrapper that fetches the current key from AWS Secrets Manager on each request (with a 30-second in-memory TTL cache). The code pattern looks roughly like:

function getApiKey(keyName: string): string {
  const cached = credentialCache.get(keyName);
  if (cached && cached.expiresAt > Date.now()) return cached.value;
  const fresh = secretsManager.getSecretValue(keyName);
  credentialCache.set(keyName, { value: fresh, expiresAt: Date.now() + 30_000 });
  return fresh;
}

This gives us a worst-case 30-second lag between secret rotation and propagation — well within the overlap window for any internal service.

Layer 2 — Event-Driven Invalidation. When a rotation event fires, we publish a message to an internal SNS topic. Subscribed services flush their credential cache immediately upon receiving the event, dropping the worst-case lag to near zero for services that are online and subscribed. Services that are offline during the event simply pick up the new key on their next cache-miss fetch — no human intervention required.

Callout: If your secrets manager doesn't support event-driven invalidation, you can approximate it with a lightweight polling loop that checks a "rotation epoch" integer stored in a fast key-value store (Redis, DynamoDB). Increment the epoch on every rotation; consumers compare their cached epoch to the current value on each request.

Kill Switches and Emergency Revocation

Planned rotation is table stakes. The harder problem is unplanned revocation — a key appears in a public GitHub repo, a vendor reports anomalous usage, a penetration test surfaces a credential in a log file.

For these scenarios, the overlap window is irrelevant. You need to revoke immediately and deal with the fallout. Our kill-switch architecture has three components:

  1. Revocation webhook receivers on every service. When our secrets orchestration layer broadcasts a KEY_REVOKED event, services drop their cached value and enter a "degraded mode" that returns a structured error to callers rather than hanging or crashing. This preserves observability during the recovery window.

  2. Feature flags tied to credential state. Any feature that exclusively depends on a now-revoked key is automatically disabled via our feature flag system until a replacement key is provisioned and confirmed healthy. Users see a degraded-but-honest UI rather than a 500 error.

  3. Automated replacement provisioning. Our on-call runbook for credential compromise triggers a GitHub Actions workflow that provisions a replacement key, writes it to Secrets Manager, and notifies the on-call engineer — target time from revocation to replacement distributed is under 4 minutes.

The Federal Reserve's guidance on operational resilience for financial institutions (SR 21-3, updated 2025) is explicit that financial technology providers should be able to demonstrate recovery time objectives for credential compromise scenarios. Four minutes is defensible; four hours is not.

Observability: Knowing When It's Safe to Retire the Old Key

The most dangerous moment in any rotation is not the issuance of the new key — it's the retirement of the old one. Teams routinely retire too early because they lack visibility into which consumers are still authenticating with the old credential.

We instrument this with three signals:

  • Per-key request counts logged at the API gateway level, broken down by key ID (not key value — never log key values). We use a short hash of the key as a stable identifier. A graph of Key A's request count trending to zero is the green light for retirement.
  • Consumer acknowledgment events. When a service successfully authenticates for the first time with Key B, it publishes an acknowledgment event. We maintain a registry of expected consumers and track acknowledgment completeness as a percentage.
  • Alerting on post-retirement Key A usage. Any authenticated request using Key A after retirement fires a PagerDuty alert. In practice, this catches consumers that were down during the rotation window and came back online still holding the old key.

Without these three signals, you're guessing. With them, retirement is a deliberate decision backed by data.

Applying This to Third-Party Fintech Integrations

The pattern above assumes you control both sides of the key lifecycle. Third-party integrations — payment processors, bank data APIs, identity verification vendors — are harder because you can't control how quickly they invalidate old keys after you request rotation.

A few tactics that have worked well for us:

  • Test rotation in staging first. Most enterprise API vendors provide sandbox environments where you can run a full rotation cycle, including overlap window verification, before touching production credentials.
  • Negotiate overlap SLAs in vendor contracts. If a vendor's key lifecycle documentation doesn't specify how long an old key remains valid after you generate a new one, ask explicitly during procurement. The answer directly determines your safe overlap window. We've walked away from integrations where the answer was "instantly" with no overlap guarantee.
  • Use a credentials proxy layer. Rather than distributing a raw vendor API key to every internal service that needs it, route all calls through a single internal proxy service. The proxy holds the credential, and internal services authenticate to the proxy with a short-lived internal token. Rotating the vendor key becomes a single-service operation rather than a fleet-wide coordination event.

For teams building on the AtlasForge Financial API, this proxy pattern maps naturally to our API gateway architecture — your internal services call your gateway, your gateway holds the AtlasForge credential, and rotation is isolated to a single configuration change.

The 30-Day Rotation Calendar

Here's how we actually schedule rotation across a diverse credential inventory without it becoming a full-time job:

  • Automated rotation: All internal service-to-service credentials, database passwords, and infrastructure secrets rotate automatically via Vault dynamic secrets or AWS Secrets Manager's native rotation lambdas. Human involvement: zero.
  • Semi-automated rotation (our primary pattern): External API keys where we control key generation. A scheduled job generates Key B and begins distribution. A human approves retirement of Key A after reviewing the observability dashboard. Total human time: ~10 minutes per credential.
  • Manual rotation with SLA tracking: Credentials that require a vendor support ticket or portal action to generate. Tracked in our security backlog with a hard 30-day SLA. An automated Jira ticket is created 7 days before expiry.

We maintain a credential inventory in a Notion database (nothing exotic — a table with key name, owner, last rotated date, next rotation date, and rotation method). It sounds unglamorous because it is. The discipline is in the consistency, not the tooling.

Bringing It Together

Zero-downtime credential rotation is not a single technique — it's a system of overlapping guarantees: dual-key overlap windows to eliminate hard cutover, dynamic secret fetching to eliminate restart dependencies, per-key observability to make retirement decisions with confidence, and kill-switch infrastructure to contain the blast radius when things go wrong.

Engineering teams that treat rotation as a 2 a.m. ceremony are paying an invisible tax: the operational risk of deferred rotation, the cognitive load of dreading it, and the eventual incident that makes the cost explicit.

If you're building integrations on the AtlasForge Financial API, our developer documentation covers our key lifecycle endpoints in detail, including the provisioning API that supports programmatic dual-key workflows. And if you're evaluating how secrets management intersects with your end-user financial data flows, the AtlasForge Financial API is designed from the ground up to support short-lived, rotatable credentials — no 365-day static tokens, no security theater. Reach out to our team if you want to walk through how rotation fits your specific integration architecture.

Ready to build on AtlasForge?

Get sandbox API keys in 60 seconds — or install the Safe to Spend 365 app.