Skip to content

Crack SDE

Most of the content are generated by AI, with human being reviewed, edited, and revised

Menu
  • Home
  • Daily English Story
  • Tech Interviews
  • Cloud Native
  • DevOps
  • Artificial Intelligence
Menu

System Design – Design Privacy Setting

Posted on 12/21/202312/29/2023 by user

On facebook, you may have noticed that you can set different privacy levels for the posts you published to be only to a specific group of users, like public, friends, friends of friends, etc

Key Features
1. Enable a user to specify the different levels of privacy for a post so that it is only visible to a particular set of users on Facebook
2. For simplicity, implement two levels of privacy , public or Friends, more complexity levels: friends of friends, and custom groups.

Design Goals

  1. Minimum latency and high consistency
  2. Due to CAP, lower the availability in the interest of high consistency
  3. Read-heavy service

Scale Estimation

  1. One billion daily active users(DAUs)
  2. Privacy level will be set by users for about two billion posts daily.
  3. Check the privacy level of about 100 billion posts daily so that they can be made visible to the correct users.

API Design
1. /setPrivacyLevel: api to set the privacy level for a post,
Params: user_id, post_id, privacy_level_enum, and timestamp
2. /canView: api to check if a user can view a particular post or not.
Params: viewer_id, post_id, and timestamp.

High Level Design


To define the different privacy levels, we will user the Enum datatype: 1. public, 2. friends, 3. friends of friends, 4. customized group. This enum will be stored a long each post in the database.

  1. To check if a post is visible to a specific user or not, review the privacy level enum:
    – If it is set to Public, then it will be visible to everyone
    – If it is set to Friends, we will check if the current user is a friend of the post’s owner, if yes, then the post will be displayed on the UI.
  2. Store the friends data of the users in a key-value store.
    – Key will be the user_id, and the value will be a set of all the friends that user has.
    – Since this data will be massive, it will be shared across multiple servers using the user_id as the key
    – Also need to discuss what will happen if a shared dies and create a fault-tolerant design.
  3. Friends of Friends
    – Given the scale of facebook, we can not enumerate through all the friends of friends as it will be extensive list and increase the system’s latency.
    – One possible way to solve this challenging problem is to perform an interaction of the post’s owner and the viewers friends lists.
    – if the intersection results in a non-empty set, then the post can be displayed.
    (from: https://www.youtube.com/watch?v=-LjbhtswNwE&t=335s)

    Scale the K-V Database
    1. Sharding:
    Distributing data across multiple machines is crucial for scalability. Sharding can be based on user ID or other unique identifiers, ensuring an even distribution of data and workload.
    2.Cluster master-replica model: To remain available when a subset of master nodes are failing or are not able to communicate with the majority of nodes, let KV Cluster uses a master-replica model where every hash slot has from 1 (the master itself) to N replicas (N-1 additional replica nodes). (source: https://redis.io/docs/management/scaling/)

    Redis Cluster automatically manages sharding and replication. It distributes data across multiple nodes, and each shard’s data is replicated to one or more other nodes.

    In the event of a node failure, Redis Cluster can continue to operate as long as at least one replica of the data is available.

    Redis Cluster also provides some degree of automated failover. If a primary node fails, one of its replicas is automatically promoted to be the new primary.
+-----------------+       +-----------------+       +-----------------+
|     Shard 1     |       |     Shard 2     |       |     Shard 3     |
|   Primary Node  |       |   Primary Node  |       |   Primary Node  |
+-----------------+       +-----------------+       +-----------------+
       /|\                       /|\                       /|\
        |                         |                         |
        | Replication             | Replication             | Replication
        |                         |                         |
       \|/                       \|/                       \|/
+-----------------+       +-----------------+       +-----------------+
| Replica Node 1  |       | Replica Node 1  |       | Replica Node 1  |
+-----------------+       +-----------------+       +-----------------+
+-----------------+       +-----------------+       +-----------------+
| Replica Node 2  |       | Replica Node 2  |       | Replica Node 2  |
+-----------------+       +-----------------+       +-----------------+

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X

Related

9

Recent Posts

  • LC#622 Design Circular Queue
  • Started with OpenTelemetry in Go
  • How Prometheus scrap works, and how to find the target node and get the metrics files
  • How to collect metrics of container, pods, node and cluster in k8s?
  • LC#200 island problem

Recent Comments

  1. another user on A Journey of Resilience

Archives

  • May 2025
  • April 2025
  • February 2025
  • July 2024
  • April 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • May 2023

Categories

  • Artificial Intelligence
  • Cloud Computing
  • Cloud Native
  • Daily English Story
  • Database
  • DevOps
  • Golang
  • Java
  • Leetcode
  • Startups
  • Tech Interviews
©2025 Crack SDE | Design: Newspaperly WordPress Theme
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}