KatInterview

Designing Access Control for Social Feed Visibility

System DesignModel answer
MediumModel answerSystem Designaccess-controlcachingsocial-graph

Last updated

Design a system that enforces per-post audience rules across feed and permalink reads at high QPS while staying correct under friendship and privacy-setting changes.

You are building the visibility layer for a large social network. Every post an author creates has an audience setting that controls who can view it.

Audience types:

  • Public: anyone can see the post.
  • Friends: only the author's direct friends.
  • Friends-of-friends (optional): direct friends plus anyone who shares a mutual friend with the author.
  • Only me: the author only.
  • Custom: an allow set (specific users, friend lists, or groups) combined with a deny set. The deny set always takes precedence.

Where enforcement applies:

  • Main feed (infinite scroll with ranked candidates).
  • Direct post permalink.
  • Any surface where post content surfaces (profile, search, notifications).

Operational requirements:

  • Privacy must be evaluated at read time against the current state of friendships, blocks, and audience settings.
  • Reads dominate: expect hundreds of thousands of feed requests per second, each ranking 200–500 candidate posts, so the system performs over 100 million visibility checks per second. Each check must be extremely fast and batchable.
  • Adding p99 latency for privacy filtering should stay under ~10 ms.
  • Friendship creation/removal and audience changes happen constantly. The system must fail closed: if data is missing or stale, never show a post to an unauthorized viewer. Over-showing after a tightening change (e.g., unfriending or narrowing an audience) must be bounded to seconds. Brief under-showing after loosening is acceptable.

Out of scope: regulatory audit trails, legal compliance logging.

Discuss the data model, the read-time enforcement path, caching strategy, and how you handle updates to relationships and audience settings.

Hints

Hint 1

Cache the inputs to the decision (friendship edges, block edges, policy objects) rather than final per-viewer-per-post results, because edge caches have precise invalidation keys while result caches have N×M cardinality.

Hint 2

Batch the visibility check per feed request: load the viewer's friend set, block set, and list memberships once, then evaluate all candidates locally against that snapshot.

Hint 3

Return 404 (not 403) when a viewer lacks access, so you don't leak the existence of a hidden post.

Hint 4

Friends-of-friends is the expensive case: consider sorted ID arrays or compressed bitmaps with early-exit intersection, and optionally a Bloom filter for fast negative pre-screening (positives must be confirmed against real edges).