Course contentsShow
← System Design
Lesson 926 of 1,91924. Authentication and Authorization at ScaleFree lesson

Access Tokens vs Refresh Tokens

Short-lived access tokens for API calls and long-lived refresh tokens for renewal.

Access Tokens vs Refresh Tokens

What you'll learn: How to balance security and usability by using two types of tokens with different lifespans in OAuth2 flows.

The Core Concept

When you authenticate, the authorization server typically issues two tokens with different purposes:

  • Access Token: A short-lived credential (minutes to hours) that your application includes with every API request to access protected resources
  • Refresh Token: A long-lived credential (days to months) that you use only to obtain new access tokens when the old ones expire

Think of an access token like a day pass to a building—it gets you in the door but expires quickly. A refresh token is like your employee badge that you use at security to get a new day pass without re-entering your full credentials.

Why This Split?

Security through short access token lifespans:

  • If an access token is stolen (intercepted in transit, leaked in logs), it becomes useless within minutes
  • Reduces the window of vulnerability significantly
  • No need to check revocation status on every request—expiration handles it

Usability through refresh tokens:

  • Users don't have to re-login every 15 minutes
  • The refresh token lives in secure storage and is only used occasionally
  • If compromised, you can revoke it server-side since refresh requests are infrequent and can afford database lookups

The Flow

  1. User logs in → receives both tokens
  2. App uses access token for API calls (no database checks needed)
  3. Access token expires → app uses refresh token to get a new access token
  4. If refresh token is invalid/revoked → user must re-authenticate

Key Takeaway: Short-lived access tokens minimize the damage from token theft, while long-lived refresh tokens maintain user convenience—together they balance security and usability in distributed systems.