MediumIntermediate

Link Aggregator / Tech News

DatabasesCachingAPI DesignSearchRate Limiting

Problem Statement

DevBoard is building a tech link aggregator (like Hacker News). Users submit links, and the community votes and discusses them. Features:

- Submit links - users post URLs with a title. The system auto-fetches metadata (description, image, domain).Voting - upvote/downvote posts and comments. Each user gets one vote per item. Vote manipulation detection.Ranking algorithm - the front page ranks posts by a time-decay formula: `score = votes / (age_in_hours + 2) ^ gravity`. Recently popular posts surface; old posts fade out. Recalculated periodically.Comments - threaded comments with upvoting and collapsible trees. Sort options: best, newest, oldest.User karma - accumulated score from upvotes on a user's posts and comments. Karma unlocks privileges (downvoting, flagging, moderation).Search - full-text search across post titles, URLs, and comments.Anti-spam - rate limit submissions, detect duplicate URLs, flag link farms, and enforce a probation period for new accounts.

Targeting 500,000 DAU with 10,000 submissions and 200,000 comments per day.

What You'll Learn

Design a Hacker News / Reddit-style link aggregator with voting, ranking, comments, and anti-manipulation measures. Build this architecture under realistic production constraints, then validate tradeoffs in the design lab simulation.

DatabasesCachingAPI DesignSearchRate Limiting

Constraints

Daily active users~500,000
Page views/day~20,000,000
Submissions/day~10,000
Comments/day~200,000
Front page load time< 200 ms
Vote recording latency< 100 ms
Availability target99.9%
ApproachClick to expand

Interview-Ready Approach

1) Clarify Scope and SLOs

  • Problem statement: Design a Hacker News / Reddit-style link aggregator with voting, ranking, comments, and anti-manipulation measures.
  • Design for a peak load target around 1,157 RPS (including burst headroom).
  • Daily active users: ~500,000
  • Page views/day: ~20,000,000
  • Submissions/day: ~10,000
  • Comments/day: ~200,000
  • Front page load time: < 200 ms

2) Capacity Planning Method

  • Convert traffic and growth constraints into request rate, storage growth, and concurrency budgets.
  • Keep at least 2-3x safety margin per tier (ingress, compute, storage, async workers).
  • Reserve explicit latency budgets per hop so p95 can be defended in review.

3) Architecture Decisions

  • Databases: Define a clear system-of-record and design read/write paths separately before adding optimizations.
  • Caching: Put cache on hot read paths first and pick cache-aside or write-through explicitly.
  • API Design: Standardize API boundaries, idempotency keys, pagination, and error contracts first.
  • Search: Use primary store for writes and async index updates for search relevance + scale.
  • Rate Limiting: Enforce token/sliding-window limits at ingress and for sensitive internal APIs.

4) Reliability and Failure Strategy

  • Use strong write constraints (transactions or conditional writes) and explicit backup/restore strategy.
  • Bound staleness with TTL + invalidation hooks for critical entities.
  • Apply strict input validation and backward-compatible versioning.
  • Track indexing lag and support reindex from source of truth.
  • Return deterministic 429 behavior with clear retry headers.

5) Validation Plan

  • Run one peak-load test, one dependency-degradation test, and one failover test.
  • Verify idempotency for all retried writes and async consumers.
  • Track user-facing SLOs first: p95 latency, error rate, and successful throughput.

6) Trade-offs to Call Out in Interviews

  • Databases: SQL gives stronger transactional guarantees; NoSQL often gives better write scaling and flexibility.
  • Caching: Higher hit rate cuts latency/cost, but stale data and invalidation bugs become primary risks.
  • API Design: Rich APIs improve developer speed but can create long-term compatibility burden.
  • Search: Search index gives rich querying but introduces eventual consistency and index ops overhead.
  • Rate Limiting: Aggressive limits protect the system but can hurt legitimate burst traffic.

Practical Notes

  • Cache the ranked front page in Redis - recompute every 30-60 seconds. Individual posts and comment trees can also be cached with TTL.
  • The ranking formula requires a periodic batch job (every minute) that re-scores top posts. Only re-score posts from the last 48 hours.
  • Store comments as a tree (parent_id reference). Flatten and nest on read. For large threads, paginate children of each comment.

Learn the Concept

Practice Next

Reference SolutionClick to reveal

Why This Solution Works

Request path: The solution keeps ingress, service logic, and stateful dependencies separated so each layer can scale independently.

Reference flow: Web Clients -> Load Balancer -> API Gateway -> Rate Limiter -> API Service -> Primary SQL DB -> Redis Cache -> Search Index

Design strengths

  • Cache sits on the read path to absorb repeated queries and keep DB pressure stable.
  • Security controls are enforced at ingress to protect downstream capacity.

Interview defense

  • This design makes bottlenecks explicit (ingress, core compute, persistence, async workers).
  • It supports progressive scaling without re-architecting the core request path.
  • It keeps correctness-sensitive state changes in durable systems while offloading background work asynchronously.