OAuth 2.0 in System Design Interviews: When to Use It and What to Say
OAuth 2.0 is a protocol that lets one service obtain limited access to a user’s resources on another service without sharing passwords. In a design interview you’ll typically bring it up when the problem involves delegated access – for example, letting a mobile app call a user's photo library stored in a cloud service, or enabling a third-party analytics dashboard to read a company's metrics.
The problem OAuth solves
Imagine you are building a photo-sharing platform that wants to let users embed their Instagram pictures in a custom gallery. The naïve solution is to ask users for their Instagram credentials and store them. That approach has three major flaws:
- Security risk – you become responsible for protecting another service’s passwords.
- User friction – users are reluctant to type credentials into a third-party site.
- Revocation difficulty – the only way a user can cut off your access is to change their Instagram password, which also locks out every other app that holds it.
OAuth 2.0 solves this by issuing a short-lived access token that the photo-sharing platform can use on the user’s behalf. The user never shares their password with the platform; they only grant permission through a consent screen hosted by Instagram.
How OAuth 2.0 works – step by step example
Below is a minimal "Authorization Code" flow for a web app that wants to read a user's Google Drive files.
- Client registration – The web app registers with Google and receives a
client_idandclient_secret. - User initiates login – The app redirects the user’s browser to Google’s authorization endpoint with parameters:
https://accounts.google.com/o/oauth2/v2/auth?
client_id=YOUR_CLIENT_ID&
redirect_uri=https://app.example.com/callback&
response_type=code&
scope=https://www.googleapis.com/auth/drive.readonly&
state=xyz- User authenticates & consents – Google shows a login screen, then a consent screen listing the requested scopes.
- Authorization code returned – After consent, Google redirects back to
https://app.example.com/callback?code=AUTH_CODE&state=xyz. - Token exchange – The app server POSTs to Google’s token endpoint:
POST https://oauth2.googleapis.com/token
grant_type=authorization_code&
code=AUTH_CODE&
redirect_uri=https://app.example.com/callback&
client_id=YOUR_CLIENT_ID&
client_secret=YOUR_CLIENT_SECRET Google responds with an access_token (an opaque string at Google; some providers issue JWTs) and, if offline access was requested, a refresh_token.
- API call – The app includes
Authorization: Bearer ACCESS_TOKENin the HTTP header when calling the Drive API. - Token refresh – When the access token expires (typically after an hour), the app uses the refresh token to obtain a new access token without user interaction.
The key ideas are delegation (Google authenticates the user), least privilege (scopes limit what the app can do), and short-lived tokens (reducing damage if a token leaks).
Classic design questions where OAuth appears
| Design Question | Where OAuth is relevant | Typical spot in the diagram |
|---|---|---|
| Social login for a SaaS product | User authentication via Google/Facebook | At the edge, before the app’s own session service, showing a redirect to the identity provider. |
| API gateway for a multi-tenant data platform | Third-party analytics tools need read-only access to tenant data | Between the gateway and the data service, labeling the token validation component. |
| Mobile app accessing a user's cloud storage | The app needs permission to read/write the user’s files | In the mobile-to-backend request path, showing the OAuth token exchange and refresh flow. |
In each case you would draw a box for the Authorization Server (e.g., Google) and a Token Validation step inside your own service, often next to the API gateway.
Trade-offs and the alternative interviewers may ask about
| Aspect | OAuth 2.0 | Alternative (e.g., API keys or custom JWT auth) |
|---|---|---|
| User experience | Single-click consent, no password sharing | Users must create/manage another credential |
| Security | Tokens are short-lived, revocable, scoped | API keys are long-lived, harder to rotate |
| Complexity | Requires redirects, token storage, refresh logic | Simpler request signing, but less flexible |
| Interoperability | Standard across many providers | Custom scheme ties you to one implementation |
Interviewers often probe the complexity side: “What if the redirect flow adds latency?” or “How would you handle token revocation at scale?” Be ready to discuss caching token introspection results, using short token lifetimes, and background revocation checks.
30-second spoken version
"OAuth 2.0 lets a service act on a user’s behalf without ever seeing the user’s password. The user is redirected to the identity provider, grants a set of scoped permissions, and the provider returns a short-lived access token (plus a refresh token). Your service validates the token on each request, and can refresh it when it expires. It’s the go-to solution for social login, third-party API access, and mobile-to-cloud interactions, trading a bit of redirect latency for tighter security and user-friendly consent."
Common mistakes candidates make
- Over-detailing the spec – Interviewers want the high-level flow, not every RFC parameter. Stick to the redirect, code, token exchange, and usage steps.
- Confusing OAuth with OpenID Connect – OIDC adds an ID token for authentication; OAuth alone only grants authorization.
- Ignoring token storage – Mention where you keep refresh tokens securely (e.g., encrypted DB) and how you rotate them.
- Skipping revocation handling – Explain how you would invalidate a token when a user revokes access, perhaps via token introspection or a revocation list.
- Reaching for the implicit flow – Current OAuth security guidance deprecates the implicit flow; single-page and mobile apps should use the Authorization Code flow with PKCE.
How to practice this
- Pick a classic design prompt (e.g., “Add Google login to a SaaS dashboard”). Sketch the request path and insert the OAuth redirect and token validation components.
- Use System Design AI’s canvas to draw the flow, then ask the AI coach to review your diagram for missing pieces.
- Run through the 30-second spoken version aloud until it feels natural, then rehearse answering follow-up trade-off questions.
Questions people ask
When should I bring up OAuth in a design interview?
Whenever the problem involves delegating user authority to a third-party service—social login, third-party analytics, or a mobile app accessing a user's cloud storage. It signals that you understand secure delegation without password sharing.
What’s the difference between the Authorization Code and Implicit flows?
Authorization Code exchanges a short-lived code for a token on a backend server, giving you refresh tokens and better security. Implicit returned the token directly to the browser and was once used for SPAs; it is now deprecated in favor of Authorization Code with PKCE.
How do I handle token revocation at scale?
Cache token introspection for a few minutes, subscribe to revocation notifications from the provider, and keep a revocation list that the API gateway checks before forwarding requests.
Can I replace OAuth with a simple API key for third-party integrations?
You can, but you lose scoped permissions, easy revocation, and a user-friendly consent flow. API keys are suited for trusted machine-to-machine calls, not for delegating user authority.