Tracing a Link Tap Through a Large Social Platform
System DesignModel answerLast updated
Explain what happens from the moment a user taps a link in a social app feed until the destination renders, covering client, network, backend, security, privacy and monitoring.
Problem
You are working on a large social networking product with billions of users. A logged-in user is browsing their feed and taps or clicks a hyperlink inside a post.
Describe, from start to finish, everything that happens until the destination is visible to the user. Your answer should be organized as a timeline and cover:
- What runs on the client when the click happens
- How the request travels across the network
- Which backend services take part and how data is fetched
- How the response is delivered and rendered
- Performance considerations
- Security and privacy considerations
- How the team would monitor the flow in production
Things to address
- State your assumptions first. For example: is the link internal (another profile or page) or external (a news article)? Is the client web or native?
- Show how the flow differs between internal and external links.
- Pick two or three areas and go deeper, including trade-offs and the numbers you would target.
- Mention at least one product trade-off, such as safety warnings versus friction for legitimate sites.
There is no single correct answer. A strong response is structured, prioritizes the interesting problems, and justifies its choices.
Hints
Hint 1
Open by clarifying the scenario (internal vs. external link, web vs. native, logged-in user) and set a latency target, so the rest of your answer has a frame.
Hint 2
Walk a strict timeline: client event handling, DNS/TLS/edge, backend authentication and data fetching, response streaming, rendering, then post-click logging. Call out where internal and external links diverge.
Hint 3
For external links, think about an intermediary redirect endpoint: what it validates, what it strips from the request, and what it logs. For internal links, think about client-side routing and prefetching.
Hint 4
Reserve time at the end for deep dives: a latency budget, tail latency from fan-out, server-side privacy checks on every object, and the cost of warning pages for legitimate publishers.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing and assumptions
I would begin by pinning down the scenario: a logged-in user on a web client clicks a link in a feed post. I would treat two cases separately, since they diverge early: an internal link (profile, page, group, event) and an external link (a third-party article). Scale assumptions: billions of users and millions of clicks per second at peak. Targets: internal navigation feels instant (roughly under 300 ms to first meaningful content), and external redirects add as little overhead as possible (tens of milliseconds).
Timeline
1. Client-side handling
- The browser fires pointer and click events. A single delegated listener at the app root dispatches to the component handler.
- Internal link: the handler calls
preventDefault()and passes the target to a client-side router, which updates the URL through the History API. No full page reload happens, and the app shell stays mounted. - External link: the anchor points to a first-party redirect endpoint (a "link shim") carrying the target URL and a signed token. It uses
rel="noopener noreferrer"so the new page cannot accesswindow.openeror see the referrer. - Click logging is sent asynchronously and batched, for example via
navigator.sendBeacon, so it never delays navigation. Fields: post ID, position in feed, surface, session. - Prefetching: on hover, touch-start or when the link enters the viewport, start fetching the route's code bundle and kick off the data query. This hides roughly 100-200 ms of work before the actual click.
2. Network path
- DNS is usually cached. On a miss, geo-aware or anycast DNS directs the user to a nearby edge point of presence.
- Transport: reused HTTP/2 or HTTP/3 connections with TLS 1.3 give 0-1 round trips on resumption. A cold connection costs about 2-3 RTTs.
- Edge: an L4 load balancer spreads connections across L7 proxies, which terminate TLS near the user and forward over the private backbone on long-lived warm connections.
- Static assets (JS chunks, CSS, images) come from a CDN with content-hashed URLs and immutable cache headers.
3. Backend
- The web tier validates the session cookie. Mutating requests also validate a CSRF token.
- The client sends a persisted query (an ID rather than query text). That saves bytes and prevents arbitrary query execution.
- The GraphQL layer fans out to services: a social-graph store (a read-optimized, geo-replicated cache in front of sharded SQL), a general object cache, ranking services, and media and ads services.
- Privacy is enforced per object on the server: audience settings, blocks, age restrictions. The client is never trusted to filter.
- External branch: the redirect endpoint verifies the signature (bound to user and time-limited, so it cannot be abused as an open redirect), checks the destination against blocklists and classifiers for malware, phishing and spam, then returns one of: a 302 to the target, an interstitial warning, or a block. It strips sensitive referrer information and logs the outbound click.
4. Response delivery
- Return JSON, ideally streamed: above-the-fold data first, secondary modules afterward (
@defer/@streamstyle). - On a cold load, server-side rendering or an inlined data payload avoids a code-then-data waterfall.
5. Rendering
- A normalized client store (Relay-style) merges the response into records; subscribed components re-render.
- The UI framework shows skeleton placeholders immediately via Suspense, then fills content in. Images are lazy-loaded with responsive sizes and modern formats.
- For external links, the third-party page loads in a new tab or an in-app browser and is outside our control.
6. After the click
- Events flow through a log pipeline into near-real-time consumers (ranking feedback, integrity signals) and the warehouse.
- The client reports performance metrics: time to visually complete, interaction latency, error counts.
Deep dives
Performance
Example internal-navigation budget: ~50 ms client work, 30-80 ms network on a warm connection, 50-150 ms backend, ~50 ms render. Levers:
- Code splitting plus route prefetch, fetching code and data in parallel rather than sequentially.
- Layered caching: browser, CDN, client store (instant back-navigation), server object cache. Hit rates above 99% in the graph cache protect the database.
- Tail latency: fan-out means the slowest dependency determines the response. Use per-call timeouts, hedged requests where safe, and partial responses (omit a failed module instead of failing the page).
- Measure p75/p95 on low-end devices and slow networks, not only on developer machines.
Security and privacy
- Signed redirect tokens, destination scanning, and referrer stripping for external links.
noopeneragainst reverse tabnabbing; rejectjavascript:and other dangerous URL schemes in user content.- XSS defenses: default output escaping, strict Content Security Policy.
- CSRF tokens, SameSite and HttpOnly/Secure cookies.
- Rate limiting and bot detection at the edge.
- Server-side privacy checks on every returned object.
Product trade-offs
- Warnings vs. friction: interstitials protect users but reduce click-through for legitimate publishers. Tune thresholds using precision/recall, add an appeal path for sites wrongly flagged, and consider softer warnings for medium-risk links.
- In-app browser vs. system browser: the in-app browser gives better measurement, safety control and speed (preloading), but users may prefer their own browser's saved passwords and extensions. Offer an easy "open in browser" option.
- Aggressive prefetching improves speed but wastes bandwidth and battery, and can inflate click metrics, so make it adaptive to network type and data-saver mode.
Observability
- Dashboards on click-to-render latency (p50/p95/p99) by surface, device class and region.
- Error rates for the redirect endpoint, blocked-link rates, and false-positive reports.
- Distributed tracing with a request ID carried from client to backend services.
- Alerts on regressions, plus canary releases and A/B tests to validate performance changes.
Common mistakes
- Reciting a generic "DNS, TCP, HTTP" list with no branch for internal vs. external links.
- Forgetting that the click handler must not block on logging.
- Treating privacy as a client-side concern.
- Skipping tail latency and failure handling (partial rendering, timeouts).
- Ignoring product trade-offs such as friction from warnings.
- Spending all the time on breadth and never going deep on any area.