Library / Case Studies

TripAdvisor Architecture - 40M Visitors, 200M Dynamic Page Views, 30TB Data - High Scalability -

This is a guest post by Andy Gelfond , VP of Engineering for TripAdvisor. Andy has been with Tr...

By High Scalability engineers · High Scalability · Added 2026-10-12

Open original source

All content belongs to High Scalability engineers / High Scalability. We only link to it and give credit. Report a problem

Learn this case study

About 37 min left. Your work is saved as you go.

What you are about to study

High Scalability explains a real system. You should know the basics: caching, queues and replication.

Ideas you will meet

Distributed Systems
Consensus, time, failure and the fundamentals of scale-out.

What we already know about this

Our own lessons on these ideas. Read them here before you start, so it makes sense.

  • Networking and Web Security Deep Dive · 13 minJWT, cookies, CORS and security headersTokens and the browser's rules: what is inside a JWT, where to store tokens, what CORS really controls and the headers worth sending.Read here

    Cookies and sessions, quickly

    A session keeps a user logged in. The usual approach: after login the server creates a random session id, stores session data server-side, and sends the id in a cookie. (Passwords and sessions are detailed in their own lesson.) Good cookie flags:

    FlagEffect
    HttpOnlyJavaScript cannot read it, limiting theft through XSS
    SecureSent only over HTTPS
    SameSite=Lax/StrictLimits cross-site sending, reducing CSRF
    Path, DomainLimit where it is sent
    Max-Age / ExpiresLifetime; keep session cookies short-lived with renewal

    JSON Web Tokens (JWT)

    A JWT is a compact, signed token with three dot-separated, base64url parts: header (algorithm), payload (claims) and signature.

    Figure SDA-NSD-04-1 · Anatomy and checking of a JWT · © forcsguy.com

    Why use them: the API can verify a token without a database lookup, which suits services and mobile apps. The cost: a stateless token is hard to revoke before it expires.

    Good practice

    • Keep access tokens short-lived (minutes) and use refresh tokens (stored carefully, rotated, revocable) to get new ones.
    • Always verify signature, exp, iss (issuer) and aud (audience); pin the algorithm.
    • A JWT is signed, not encrypted: do not put sensitive data in it (use JWE if you must encrypt).
    • Where to store in a browser: HttpOnly cookies resist XSS theft but need CSRF protection; localStorage is readable by any script, so an XSS leaks the token. There is no perfect answer: choose with your threat model, and prevent XSS first.
    • For simple server-rendered apps, server-side sessions are often simpler and easier to revoke than JWTs. (Federated login with OAuth and OpenID Connect is in the SSO lesson.)

    Same-origin policy and CORS

    Browsers enforce the same-origin policy: a page from one origin (scheme, host and port) cannot read responses from another origin. CORS (cross-origin resource sharing) is how a server opts in to being read by specific other origins.

    Figure SDA-NSD-04-2 · A cross-origin request with a preflight · © forcsguy.com

    Key points:

    • CORS protects users' browsers, not your server. It does not stop curl, scripts or other servers from calling your API; you still need authentication and authorisation.
    • A simple request (GET or simple POST with plain headers) is sent directly; the browser only decides whether the page may read the response. Other requests get a preflight.
    • Configure exact origins, not *, when credentials are involved. Access-Control-Allow-Credentials: true cannot be combined with *. Never blindly echo the Origin header.
    • Limit allowed methods and headers; cache preflights with Access-Control-Max-Age.

    Security headers worth sending

    HeaderPurpose
    Strict-Transport-SecurityTell browsers to use HTTPS only for your domain
    Content-Security-PolicyRestrict script, style, frame and connection sources; mitigates XSS and clickjacking
    X-Content-Type-Options: nosniffStop browsers guessing content types
    Referrer-PolicyLimit referrer information sent to others
    Permissions-PolicyTurn off powerful browser features you do not use
    Cross-Origin-Opener-Policy / Cross-Origin-Resource-PolicyIsolate your pages from other origins

    Caching headers and compression

    • Cache-Control controls caching: public, max-age=31536000, immutable for fingerprinted static files; no-store for sensitive responses; private for per-user responses that shared caches must not store. ETag / Last-Modified allow cheap revalidation (a 304 response with no body).
    • Compression (gzip, Brotli) shrinks text responses a lot. One caution: compressing responses that mix secrets with attacker-controlled text over TLS can enable attacks such as BREACH, so avoid reflecting secrets and use per-request tokens.
    • Do not cache authenticated pages in shared caches by accident; set Vary correctly.

    Checklist

    Cookies: HttpOnly, Secure, SameSite. Tokens: short-lived, verified fully, no secrets inside. CORS: exact origins, minimal methods. Headers: HSTS, CSP, nosniff, frame protection. Caching: private or no-store for user data.

    Real-world reading

    Open this lesson with its quiz and exercise

Go deeper on this

A path through videos, articles, other case studies and code on the same ideas as TripAdvisor Architecture - 40M Visitors, 200M Dynamic Page Views, 30TB Data - High Scalability -.

  1. Warm upGet the vocabulary first.

  2. WatchHow others solve the same problem, on video.

    Videos belong to their creators and play from YouTube. More on YouTube (opens in a new tab)

  3. ReadEngineers explain it in their own words.

  4. See it in another companyThe same ideas, a different system.

  5. Read the codeSee how it looks when it is real.

Keep learning

Loading community…