🖥️
Sunil Notebook
Interview Preparation
  • 📒Notebook
    • What is this about ?
  • System Design
    • 💡Key Concepts
      • 🌐Scalability
      • 🌐Latency Vs Throughput
      • 🌐Databases
      • 🌐CAP Theorem
      • 🌐ACID Transactions
      • 🌐Rate limiting
      • 🌐API Design
      • 🌐Strong Vs eventual consistency
      • 🌐Distributed tracing
      • 🌐Synchronous Vs asynchronous Communication
      • 🌐Batch Processing Vs Stream Processing
      • 🌐Fault Tolerance
    • 💎Building Blocks
      • 🔹Message
      • 🔹Cache
      • 🔹Load Balancer Vs API Gateway
    • 🖥️Introduction to system design
    • ⏱️Step By Step Guide
    • ♨️Emerging Technologies in System Design
    • ☑️System design component checklist
      • 🔷Azure
      • 🔶AWS
      • ♦️Google Cloud
    • 🧊LinkedIn feed Design
    • 🏏Scalable Emoji Broadcasting System - Hotstar
    • 💲UPI Payment System Design
    • 📈Stock Broker System Design - Groww
    • 🧑‍🤝‍🧑Designing Instagram's Collaborative Content Creation - Close Friends Only
    • 🌳Vending Machines - Over the air Systems
    • Reference Links
  • DSA
    • Topics
      • Introduction
      • Algorithm analysis
        • Asymptotic Notation
        • Memory
      • Sorting
        • Selection Sort
        • Insertion Sort
        • Merge Sort
        • Quick Sort
        • Quick'3 Sort
        • Shell Sort
        • Shuffle sort
        • Heap Sort
        • Arrays.sort()
        • Key Points
        • Problems
          • Reorder Log files
      • Stacks and Queues
        • Stack Implementations
        • Queue Implementations
        • Priority Queues
        • Problems
          • Dijkstra's two-stack algorithm
      • Binary Search Tree
        • Left Leaning Red Black Tree
          • Java Implementations
        • 2-3 Tree
          • Search Operation - 2-3 Tree
          • Insert Operation - 2-3 Tree
        • Geometric Applications of BST
      • B-Tree
      • Graphs
        • Undirected Graphs
        • Directed Graphs
        • Topological Sort
      • Union Find
        • Dynamic Connectivity
        • Quick Find - Eager Approach
        • Quick Find - Lazy Approach
        • Defects
        • Weighted Quick Union
        • Quick Union + path comparison
        • Amortized Analysis
      • Convex Hull
      • Binary Heaps and Priority Queue
      • Hash Table vs Binary Search Trees
  • Concurrency and Multithreading
    • Introduction
    • Visibility Problem
    • Interview Questions
    • References
      • System design
  • Design Patterns
    • ℹ️Introduction
    • 💠Classification of patterns
    • 1️⃣Structural Design Patterns
      • Adapter Design Pattern
      • Bridge Design Pattern
      • Composite Design Pattern
      • Decorator Design Pattern
      • Facade Design Pattern
      • Flyweight Design Pattern
      • Private Class Data Design Pattern
      • Proxy Design Pattern
    • 2️⃣Behavioral Design Patterns
      • Chain Of Responsibility
      • Command Design Pattern
      • Interpreter Design Pattern
      • Iterator Design Pattern
      • Mediator Design Pattern
      • Memento Design Pattern
      • Null Object Design Pattern
      • Observer Design Pattern
      • State Design Pattern
      • Strategy Design Pattern
      • Template Design Pattern
    • 3️⃣Creational Design Patterns
      • Abstract Factory Design Pattern
      • Builder Design Pattern
      • Factory Method Design Pattern
      • Object Pool Design Pattern
      • Prototype Design Pattern
      • Singleton Design Pattern
    • Java Pass by Value or Pass by Reference
  • Designing Data-Intensive Applications - O'Reilly
    • Read Me
    • 1️⃣Reliable, Scalable, and Maintainable Applications
      • Reliability
      • Scalability
      • Maintainability
      • References
    • 2️⃣Data Models and Query Languages
      • Read me
      • References
    • Miscellaneous
  • Preparation Manual
    • Disclaimer
    • What is it all about?
    • About a bunch of links
    • Before you start preparing
    • Algorithms and Coding
    • Concurrency and Multithreading
    • Programming Language and Fundementals
    • Best Practices and Experience
  • Web Applications
    • Typescript Guidelines
  • Research Papers
    • Research Papers
      • Real-Time Data Infrastructure at Uber
      • Scaling Memcache at Facebook
  • Interview Questions
    • Important links for preparation
    • Google Interview Questions
      • L4
        • Phone Interview Questions
      • L3
        • Interview Questions
      • Phone Screen Questions
  • Miscellaneous
    • 90 Days Preparation Schedule
    • My Preparation for Tech Giants
    • Top Product Based Companies
  • Links
    • Github
    • LinkedIn
Powered by GitBook
On this page
  • Scope and Requirements
  • Functional Requirements:
  • Non-Functional Requirements:
  • Envelope Calculations
  • Storage requirements
  • High Level System design
  • Component Design
  • Scalability and Reliability
  • Security Considerations
  • Monitoring and Maintenance
  • Trade-offs and Considerations
  • References

Was this helpful?

Edit on GitHub
  1. System Design

Designing Instagram's Collaborative Content Creation - Close Friends Only

PreviousStock Broker System Design - GrowwNextVending Machines - Over the air Systems

Last updated 10 months ago

Was this helpful?

No need of introduction on what is instagram ? But needs introduction for Close Friends only feature.

Designing Instagram's 'Close Friends Only' feature involves creating a system where users can make a list of close friends. When they share content, the system checks this list to ensure only those friends can see it. This requires quick data access and strong security measures to keep the shared content private and secure.

This feature is now available across the streaming platforms like Spotify, Youtube, IHeartRadios and apple podcasts.

During the interview, please follow the below steps:

  • Understand the Problem

  • Define the Scope and Requirements

  • Envelope Calculations

  • High-Level System Design

  • Component Design

  • Scalability and Reliability

  • Security Considerations

  • Monitoring and Maintenance

  • Trade-offs and Considerations

Scope and Requirements

Functional Requirements:

  • Users can add or remove friends from their close friends list.

  • Users can share content visible only to close friends.

  • Close friends receive notifications for shared content.

Non-Functional Requirements:

  • Low-latency access to close friends list.

  • High availability and reliability.

  • Secure data transmission and storage

Envelope Calculations

As of 2024 by statista there are 2 Billion users in the instagram. People spend lot of time in instagram assume 60% (1.2 Billion ) of the users active and also considering 50 average users in the close friends list.

Not all the users list will be active all the time assume 20% of active users (240 million users). Considering 10% of the users posted i.e (24 million posts/day).

Lets understand the storage requirements.

Storage requirements

Consider 1KB of each user profile data (including user ID, name, profile picture URL, etc.) so for 2 Billion users we need atleast 2 Billion * 1 KB which is around 2 TB.

Lets do storage requirement for close friends, store only user Id ( 20 Bytes ), for one user needs around 50 * 20 B = 1 KB.

for 2 Billion users we need 2 B * 1KB = 2 TB

Now lets do media storage requirement, Assume these are the content ( photo - 1 MB , Video - 10 MB, Story - 5 MB ). Lets do some content distribution - Photos 70%, Videos 20%, story 10%.

Photos:

Posts/day: 24 million * 70% = 16.8 million

Storage/day: 16.8 million * 1 MB = 16.8 TB/day

Annual storage: 16.8 TB/day * 365 days = 6132 TB = ~6.1 PB/year

Videos:

Posts/day: 24 million * 20% = 4.8 million

Storage/day: 4.8 million * 10 MB = 48 TB/day

Annual storage: 48 TB/day * 365 days = 17520 TB = ~17.5 PB/year

Stories:

Posts/day: 24 million * 10% = 2.4 million

Storage/day: 2.4 million * 5 MB = 12 TB/day

Annual storage: 12 TB/day * 365 days = 4380 TB = ~4.4 PB/year

Total storage requried - 6.1 PB + 17.5 PB + 4.4 PB = 28 PB / Year

Considering the social media platform like instagram, bandwith calculations are important. Assume 50 Views per post.

We should consider upload and download bandwidth

Upload:

Photos: 16.8 million * 1 MB = 16.8 TB

Videos: 4.8 million * 10 MB = 48 TB

Stories: 2.4 million * 5 MB = 12 TB

Total Daily Upload: 16.8 + 48 + 12 = 76.8 TB/day

Download:

Daily Views:

Photos: 16.8 million * 50 = 840 million

Videos: 4.8 million * 50 = 240 million

Stories: 2.4 million * 50 = 120 million

Daily Download Volume:

Photos: 840 million * 1 MB = 840 TB

Videos: 240 million * 10 MB = 2400 TB

Stories: 120 million * 5 MB = 600 TB

Total Daily Download: 840 + 2400 + 600 = 3840 TB/day = 3.84 PB/day

Total Bandwidth: 3.92 PB / day

High Level System design

List of microservices required for this feature

Microservices:

  • User Service

  • Close Friends Service

  • Content Service

  • Access Control Service

  • Notification Service

  • Frontend Service

Component Design

Microservices, Load Balancer, Storage, Caching

For user management - Relational DB - MySQL Database

For Close Friends - Relation DB - MySQL Database

For Content Sharing - Front end communicating to the content service.

Content Metadata will be stored in NoSQL and files in the distributed storage and content will be served via CDN.

For Notifications, notifications service will be communicated with kafka to listen the content sharing activities. and notifications will be shared only to close friends.

Studio Link:

Scalability and Reliability

Load Balancers: Distribute requests across multiple servers.

Database Sharding: Split databases to handle high traffic.

Caching: Use Redis for quick access to frequently accessed data.

CDN: Deliver media content quickly and reliably.

Security Considerations

Encryption is very important considering the videos and photos shared only to group of users. Encrypt the data in transit using TLS. TLS, is a widely adopted security protocol designed to facilitate privacy and data security for communications over the Internet.

Coming to the access control, Strict checks to ensure only authorized users access content. Considering the security modifications to access need to be audited for compliance requirements.

Monitoring and Maintenance

Collecting logs for monitoring system health and debugging. Monitor key performance indicators such as latency, error rates, and throughput. Setting up alerts for unusual activity or performance degradation.

Trade-offs and Considerations

Considering the feature like close friends only, below trade off are worth to discuss.

Performance VS Security: Balancing quick access with strong security measures.

Consistency VS Availability: Using eventual consistency for high availability.

Storage Costs: Managing the cost of storing large amounts of media content.

References

🧑‍🤝‍🧑
⏱️Step By Step Guide
https://about.instagram.com/blog/announcements/renee-rapp-rachel-sennott-on-close-friends-feature
https://www.statista.com/topics/1882/instagram/
https://www.cloudflare.com/learning/ssl/transport-layer-security-tls/