Authentication is one of those things every application needs. Self-hosting an authentication service like Keycloak usually means running one or more EC2 instances, a PostgreSQL database, a load balancer, patching, and capacity planning. Managed providers like Auth0 take that burden away, but bring per-user pricing and a dependency you don't control.
Is it possible to build a serious identity provider without running any servers?
To answer this question for myself, I wrote LiteLogin, an open-source, multi-tenant identity provider that runs entirely on serverless technologies. I wanted something with little to no maintenance, a bill that follows usage, and standard OAuth 2.1 and OpenID Connect that any application can integrate with.
The architecture
flowchart LR user(["Browser or app"]) -- "Host: login.acme.com" --> edge["CloudFront + WAF<br/>sets trusted host header<br/>adds origin secret"] edge --> auth["Auth Lambda<br/>rejects requests<br/>without the secret"] auth --> db[("DynamoDB")] auth --> kms["KMS"] auth --> ses["SES"] operator(["Operator CLI"]) -- "IAM (SigV4)" --> admin["Admin Lambda"] admin --> db The architecture is straightforward. The browser reaches CloudFront, which terminates TLS and runs the WAF. CloudFront forwards the request to the Auth Lambda, which serves every public page and endpoint. The Lambda reads a few items from DynamoDB, verifies the user's credentials, and redirects back to the application with an authorization code. When the application exchanges that code for tokens, the Lambda asks KMS to sign them.
Why Lambda? Each invocation is independent. No correctness-critical state lives in Lambda memory, so there's nothing to replicate, drain, or patch.
Why DynamoDB? Every request requires a handful of lookups by key and single-item conditional writes. DynamoDB handles both in milliseconds without connection pools or a database server to upgrade.
Why KMS? The signing key is among the most valuable assets in an identity provider. Anyone able to use it can mint tokens trusted by every application that trusts the issuer. With KMS, the private key never exists outside KMS.
The data model
erDiagram ORG ||--o{ POOL : has ORG ||--o{ CLIENT : has ORG ||--|{ LOGIN_HOST : has LOGIN_HOST }o--|| POOL : "signs in to" CLIENT }o--|| POOL : uses POOL ||--o{ USER : contains An org is a tenant. It has user pools, clients, and login hosts. Each host serves one user pool, and applications on the same login host share a sign-in page.
There are two tables, split by how long things live:
- Config holds durable records that last until someone deletes them: orgs, apps, hosts, users, and keys. Its change stream drives background jobs.
- Sessions holds short-lived security artifacts: browser sessions, authorization codes, and refresh tokens. TTL eventually removes expired records without requiring application-level cleanup. Expiration is enforced by the application, not dependent on TTL deletion.
Signing in
Each user is stored under a random ID, USER#{id}. To find a user by email, there's a second small item, POOL#{pool}#EMAIL#{email}, that holds just the user ID. Both are written together, with a condition that the email item doesn't already exist within a pool.
A sign-in is two direct reads: email item, then user. A secondary index could do the lookup, but DynamoDB indexes are only eventually consistent, and "can this person sign in?" shouldn't depend on a value that might be a second out of date.
A code works once
When an application redeems an authorization code, LiteLogin marks the code used and creates the refresh token in a single transaction:
Update CODE#{hash} SET used_at IF used_at doesn't exist yet Check USER#{id} IF the user is active and hasn't been signed out since Put the new refresh token family and its first token If two requests race with the same code, DynamoDB lets exactly one through. The loser detects that the code has already been redeemed and revokes the token family created by the winner.
This also provides replay detection: a second redemption of the same code invalidates the token family created by the first redemption. No locks, just conditional writes.
Invalidate sessions and refresh tokens with one write
Every user has a counter, auth_version. Each session, code, and token family records the counter's value when it was created, and is valid only while it still matches.
Revocation becomes one write instead of a search-and-delete operation that can race with new sign-ins. Since those requests read the user anyway, there is no practical additional cost.
Access tokens are the exception. They're self-contained JWTs that applications verify locally against the published keys, without calling LiteLogin, so bumping a counter in DynamoDB can't reach them. An access token that's already been issued stays valid until it expires. That's why access tokens last 15 minutes by default, and why refresh, which does check the counter, is where revocation takes effect.
Multi-tenant SaaS with CloudFront
LiteLogin serves many tenants (orgs) from a single deployment. The tenant is routed based on the login host.
Every org gets a default host such as <my-org>.example.com. One CloudFront distribution with a wildcard certificate serves all of them, so adding an org needs no new infrastructure.
Orgs can also bring their own domain, like login.acme.com. That needs a certificate per domain, and this is where CloudFront's multi-tenant distributions come in. Each custom domain becomes a tenant of one shared distribution, with a certificate CloudFront manages.
Two details keep tenants apart:
- The host can't be forged. Lambda doesn't trust the browser's
Hostheader directly. A small CloudFront Function copies it into a dedicated header, overwriting anything the browser sent, and the Lambda trusts only that value. - CloudFront can't be bypassed. The Lambda function URL is technically public. CloudFront adds a secret origin header to every request it forwards, and Lambda rejects requests without it. This prevents someone from calling the function directly to bypass the WAF.
The origin secret protects the direct-origin path as long as it remains confidential and is properly managed.
Adding a tenant doesn't require deploying another application or creating another distribution. Tenant isolation is handled through hostname-based routing and application-level boundaries.
Each host is its own OpenID Connect issuer (iss = https://login.acme.com) and its own single sign-on boundary: the session cookie belongs to that host only, so signing in to one app signs you in to every app on that host, and to no other org's.
Does it hold up?
Before running a load test, I had to ask AWS to raise my Lambda concurrency quota from 10 to 1,000.
The load test runs the full browser authorization flow for each sign-in, plus refresh token grants, at a fixed arrival rate. Each sign-in generates five HTTP requests, so 50 sign-ins per second plus 200 refresh grants per second produces 450 requests per second.
| Region | us-east-1 |
| Load | 50 sign-ins and 200 refreshes per second (450 requests per second) |
| Duration | 5 minutes measured, after a 1-minute ramp |
| Lambda | arm64, 1 GB, no provisioned concurrency (cold starts included); concurrency peaked at 91 |
| Measured at | The client, end to end through CloudFront, from one machine |
| Errors and throttles | None (Lambda, DynamoDB, KMS) |
| Step | p50 | p99 |
|---|---|---|
GET /authorize | 25 ms | 72 ms |
POST /login (password check) | 118 ms | 164 ms |
POST /token (code exchange) | 63 ms | 114 ms |
POST /token (refresh) | 65 ms | 137 ms |
These are client-observed response times, including network and service overhead, rather than Lambda execution durations.
Conclusion
So, can you build a serious OAuth 2.1 and OpenID Connect provider without persistent servers? I think so.
An identity provider is a state machine more than a server. It checks credentials, makes conditional state changes, signs tokens, and keeps tenants apart. None of that needs a process that stays up. It comes down to a few conditional writes on keyed items, plus a signing step that's better done by KMS anyway.
Get those right, and the servers can disappear.
LiteLogin is open source and available on GitHub. If you're interested in serverless architecture, identity infrastructure, or just want to see how far you can take AWS Lambda and DynamoDB, I'd love to hear your thoughts.
