Instagram System Design Interview

System Design Instagram

If we are not prepared for a Systems Design interview, it’s tough to be able to design Instagram in a 45-minute interview. That’s why we need to know the fundamentals of Systems Design and understand this interview’s rules.

One rule we must remember is that we will have to ask the interviewer questions, assuming we will use the main features from Instagram. Then, we will take notes of those main features and finally create the system’s design.

Let’s go through the process of creating Instagram in this article.

Clarifying Questions to Design Instagram.

As I mentioned, remember it’s a 45-minute interview, so we must assume we will design Instagram only with the essential features. Let’s explore some of the core Instagram features.

User Registration and Authentication:

  • How will users create an account and log in to the system?
  • What information will be required during the registration process?
  • Will there be any validation or verification steps for user accounts?

Profile Management

  • How will users create and update their profile information?
  • What profile details will be available to other users?
  • Will users have the ability to customize their profile appearance?

Photo/Video Upload

  • How will users upload photos or videos to the system?
  • What formats and sizes will be supported for media uploads?
  • Should users have the option to add captions or tags to their posts?

News Feed and Timeline

  • How will the system generate and display the user’s personalized news feed?
  • What factors will influence the content and order of posts in the feed?
  • Will the feed support pagination or infinite scrolling?

Social Interactions

  • How will users like or comment on posts?
  • Will a notification system inform users of interactions on their posts?
  • Can users follow other users to see their posts in their feeds?

Search and Discovery

  • How will users search for specific users, posts, or hashtags?
  • Will there be a recommendation system to suggest users or content to follow?
  • Can users filter search results based on different criteria?

Direct Messaging

  • How will users send private messages to each other?
  • Will there be real-time messaging capabilities?
  • Can users share media or other content within direct messages?

Privacy and Security

  • How will the system handle privacy settings for user accounts and posts?
  • What measures will be taken to prevent unauthorized access to user data?
  • Will there be reporting and moderation features to handle inappropriate content?

Notifications

  • How will the system handle notifications for various user activities?
  • Will users receive notifications for likes, comments, or new followers?
  • Can users customize their notification preferences?

Performance and Scalability

  • How will the system handle a large number of concurrent users and posts?
  • Will the system employ caching mechanisms to improve performance?

We don’t need to ask all of those questions. We can assume we will design only Photo/Video Upload, News Feed and Timeline, Social Interactions, performance, and Scalability.

Endpoints for the Essential Instagram Features
Photo/Video Upload
  1. Upload Media Endpoint:
    • Purpose: This endpoint is responsible for receiving and storing the uploaded photo or video file in the system.
    • HTTP Method: POST
    • URL: /api/upload-media
    • Request Parameters:
      • File: The binary data of the photo or video file.
      • Metadata: Additional metadata related to the media file (e.g., user ID, timestamp).
    • Response: Returns a unique identifier or URL for the uploaded media file.
  2. Add Caption and Tags Endpoint:
    • Purpose: This endpoint allows users to add captions and tags to their uploaded posts.
    • HTTP Method: POST
    • URL: /api/posts/{post_id}/add-caption-tags
    • Request Parameters:
      • Post ID: The unique identifier of the post to which the caption and tags should be added.
      • Caption: The text content of the caption.
      • Tags: A list of tags associated with the post (e.g., #travel, #food).
    • Response: Returns the updated post object with the added caption and tags.

News Feed and Timeline

  1. Get News Feed Endpoint:
    • Purpose: This endpoint retrieves the personalized news feed for a specific user.
    • HTTP Method: GET
    • URL: /api/news-feed
    • Request Parameters:
      • User ID: The unique identifier of the user for whom the news feed is being retrieved.
      • Pagination Parameters (optional): Parameters to specify the number of posts per page and the page number.
    • Response: Returns a list of posts in the user’s news feed, ordered by relevance or recency.
  2. Get Post Details Endpoint:
    • Purpose: This endpoint retrieves the details of a specific post.
    • HTTP Method: GET
    • URL: /api/posts/{post_id}
    • Request Parameters:
      • Post ID: The unique identifier of the post for which details are being retrieved.
    • Response: Returns the detailed information of the specified post, including the post content, author, likes, comments, etc.
  3. Like Post Endpoint:
    • Purpose: This endpoint allows a user to like a specific post.
    • HTTP Method: POST
    • URL: /api/posts/{post_id}/like
    • Request Parameters:
      • User ID: The unique identifier of the user who is liking the post.
      • Post ID: The unique identifier of the post being liked.
    • Response: Returns the updated post object with the incremented like count.
  4. Comment on Post Endpoint:
    • Purpose: This endpoint allows a user to comment on a specific post.
    • HTTP Method: POST
    • URL: /api/posts/{post_id}/comment
    • Request Parameters:
      • User ID: The unique identifier of the user who is commenting.
      • Post ID: The unique identifier of the post being commented on.
      • Comment Text: The text content of the comment.
    • Response: Returns the updated post object with the added comment.
  5. Pagination Endpoint:
    • Purpose: This endpoint supports pagination functionality for the news feed.
    • HTTP Method: GET
    • URL: /api/news-feed?page={page_number}&limit={number_of_posts}
    • Request Parameters:
      • Page Number: The page number of the news feed.
      • Number of Posts: The maximum number of posts to be returned per page.
    • Response: Returns a subset of posts based on the specified pagination parameters.

Social Interactions

  1. Like Post Endpoint:
    • Purpose: This endpoint allows a user to like a specific post.
    • HTTP Method: POST
    • URL: /api/posts/{post_id}/like
    • Request Parameters:
      • User ID: The unique identifier of the user who is liking the post.
      • Post ID: The unique identifier of the post being liked.
    • Response: Returns the updated post object with the incremented like count.
  2. Comment on Post Endpoint:
    • Purpose: This endpoint allows a user to comment on a specific post.
    • HTTP Method: POST
    • URL: /api/posts/{post_id}/comment
    • Request Parameters:
      • User ID: The unique identifier of the user who is commenting.
      • Post ID: The unique identifier of the post being commented on.
      • Comment Text: The text content of the comment.
    • Response: Returns the updated post object with the added comment.
  3. Get Post Interactions Endpoint:
    • Purpose: This endpoint retrieves the likes and comments for a specific post.
    • HTTP Method: GET
    • URL: /api/posts/{post_id}/interactions
    • Request Parameters:
      • Post ID: The unique identifier of the post for which interactions are being retrieved.
    • Response: Returns a list of likes and comments associated with the specified post.
  4. Follow User Endpoint:
    • Purpose: This endpoint allows a user to follow another user.
    • HTTP Method: POST
    • URL: /api/users/{user_id}/follow
    • Request Parameters:
      • Follower User ID: The unique identifier of the user who wants to follow another user.
      • Followed User ID: The unique identifier of the user being followed.
    • Response: Returns the updated information for the follower and followed users.
  5. Get User Followers Endpoint:
    • Purpose: This endpoint retrieves the list of followers for a specific user.
    • HTTP Method: GET
    • URL: /api/users/{user_id}/followers
    • Request Parameters:
      • User ID: The unique identifier of the user for whom followers are being retrieved.
    • Response: Returns a list of users who are followers of the specified user.
  6. Get User Following Endpoint:
    • Purpose: This endpoint retrieves the list of users that a specific user is following.
    • HTTP Method: GET
    • URL: /api/users/{user_id}/following
    • Request Parameters:
      • User ID: The unique identifier of the user for whom following users are being retrieved.
    • Response: Returns a list of users that the specified user is following.
  7. Get User Feed Endpoint:
    • Purpose: This endpoint retrieves the posts from the users that a specific user is following.
    • HTTP Method: GET
    • URL: /api/users/{user_id}/feed
    • Request Parameters:
      • User ID: The unique identifier of the user for whom the feed is being retrieved.
      • Pagination Parameters (optional): Parameters to specify the number of posts per page and the page number.
    • Response: Returns a list of posts from the users that the specified user is following, ordered by relevance or recency.
  8. Notification System Endpoint:
    • Purpose: This endpoint sends notifications to users for interactions on their posts.
    • HTTP Method: POST
    • URL: /api/notifications
    • Request Parameters:
      • User ID: The unique identifier of the user who will receive the notification.
      • Notification Type: The type of interaction (e.g., like, comment) triggering the notification.
      • Post ID: The unique identifier of the post associated with the interaction.
    • Response: Returns the status of the notification delivery.

Instagram DB Design

Instagram DB Design Diagram with Essential Features

Cloud Technologies for Instagram

Let’s now explore the Microservices of Instagram being used with cloud services. If you are unfamiliar with Microservices, take a look at the following article:
The Ultimate Guide of Microservices Technologies for Java Developers

Media Service

Components: S3 Bucket, Media DB, CloudFront

Functionality:

  • S3 Bucket: Stores the actual media files (images, videos) uploaded by users in a scalable and durable storage solution.
  • Media DB: Manages metadata associated with each media file, such as user IDs, tags, and other descriptive data.
  • CloudFront: A CDN that serves media to users with low latency and high transfer speeds by caching content at edge locations close to the end users.

Summary: The Media Service is responsible for handling all user-uploaded media. Media files are stored in the S3 bucket, while the associated metadata is stored in the Media DB. When a user accesses media, CloudFront delivers the content quickly by serving it from the nearest edge location.

User Service

Components: User DB

Functionality:

  • User DB: Stores user profile information, authentication details, and other user-specific settings and preferences.

Summary: The User Service manages user accounts, including sign-up, login, profile edits, and account settings. Data is persisted in the User DB, which is designed to handle high transaction rates and complex queries involving user data.

News Feed Service

Components: Redis Cache, News Feed DB, Cassandra DB

Functionality:

  • Redis Cache: Temporarily stores popular or frequently accessed data to reduce latency and improve the speed of news feed delivery.
  • News Feed DB: Handles the logic of aggregating and serving the news feed to users. It might store user timelines and actions, such as posts they’ve made or interacted with.
  • Cassandra DB: A highly available and scalable NoSQL database that can manage large volumes of data across distributed systems. It’s used for storing the news feed data in a way that supports quick reads and writes.

Summary: The News Feed Service is responsible for aggregating and displaying the flow of posts from the users and pages that an individual follows. Redis is used to cache data for quick retrieval, while the News Feed DB, likely built on top of Cassandra, ensures that the data is scalable and resilient to high volumes of requests.

Social Service

Components: SNS, Lambda, Social DB (Neo4j)

Functionality:

  • SNS (Simple Notification Service): A pub/sub messaging service that coordinates and manages the delivery of messages to subscribing endpoints or clients.
  • Lambda: Serverless compute service that runs code in response to events, such as a new post or comment, without provisioning or managing servers.
  • Social DB (Neo4j): A graph database that efficiently stores and queries data with complex relationships, like social graphs, recommendation engines, etc.

Summary: The Social Service is integral for the interactive aspects of Instagram, like comments, likes, and direct messages. SNS orchestrates the notifications, while Lambda functions can be triggered to execute business logic, such as updating the social graph stored in Neo4j, upon specific actions or events. Neo4j is adept at handling complex social relationships and inherently network-based queries.

Each microservice is designed to handle its respective domain, ensuring the system is modular, scalable, and fault-tolerant. This separation of concerns allows Instagram to scale individual services as needed and maintain a fast and reliable platform.

Instagram System Design Diagram

Summary

Designing Instagram is not an easy task. It’s even more challenging to design it in 45 minutes. But to land a good job we need to get good at this. To help you remember the concepts we saw, let’s recap:

  • Preparation for Systems Design interview is crucial, especially for designing complex systems like Instagram in a short time frame.
  • Fundamental knowledge of Systems Design and the specific rules of the interview are necessary.
  • Key steps:
    • Ask the interviewer about essential Instagram features to focus on.
    • Take notes on the main features.
    • Design the system accordingly.

Clarifying questions for designing essential features of Instagram:

  • User Registration and Authentication: Account creation, login procedures, required information, and validation.
  • Profile Management: Profile creation, update mechanisms, visibility of details, and customization options.
  • Photo/Video Upload: Media upload process, supported formats and sizes, options for captions and tags.
  • News Feed and Timeline: News feed generation, influencing factors for post ordering, pagination or infinite scrolling.
  • Social Interactions: Liking, commenting, notification systems, and following other users.
  • Search and Discovery: User and content search functionalities, recommendation systems, search result filters.
  • Direct Messaging: Private messaging, real-time capabilities, content sharing within messages.
  • Privacy and Security: Privacy settings, data access prevention, content moderation.
  • Notifications: Handling of activity notifications, customizable preferences.
  • Performance and Scalability: Concurrent user and post management, caching strategies.
  • Focus only on Photo/Video Upload, News Feed and Timeline, Social Interactions, Performance, and Scalability for design.
  • API endpoints for essential Instagram features:

    • Photo/Video Upload:
      • Upload Media Endpoint: POST /api/upload-media for storing media files.
      • Add Caption and Tags Endpoint: POST /api/posts/{post_id}/add-caption-tags for adding captions and tags.
    • News Feed and Timeline:

      • Get News Feed Endpoint: GET /api/news-feed for retrieving user-specific feeds.
      • Get Post Details Endpoint: GET /api/posts/{post_id} for detailed post information.
      • Like Post Endpoint: POST /api/posts/{post_id}/like for liking a post.
      • Comment on Post Endpoint: POST /api/posts/{post_id}/comment for commenting on a post.
      • Pagination Endpoint: GET /api/news-feed?page={page_number}&limit={number_of_posts} for feed pagination.
    • Social Interactions:
      • Like Post Endpoint: POST /api/posts/{post_id}/like for post likes.
      • Comment on Post Endpoint: POST /api/posts/{post_id}/comment for post comments.
      • Get Post Interactions Endpoint: GET /api/posts/{post_id}/interactions for retrieving likes and comments.
      • Follow User Endpoint: POST /api/users/{user_id}/follow for following a user.
      • Get User Followers Endpoint: GET /api/users/{user_id}/followers for a list of followers.
      • Get User Following Endpoint: GET /api/users/{user_id}/following for a list of followed users.
      • Get User Feed Endpoint: GET /api/users/{user_id}/feed for a feed from followed users.
      • Notification System Endpoint: POST /api/notifications for sending user notifications.
    • Instagram DB Design: Cloud Technologies for Instagram
      • Media Service:
        • Components: S3 Bucket, Media DB, CloudFront.
        • Functionality:
          • S3 Bucket stores media files; durable and scalable.
          • Media DB holds media metadata like user IDs, tags.
          • CloudFront is a CDN for low-latency, high-speed media delivery.
        • Summary: Handles user media uploads; S3 for storage, Media DB for metadata, CloudFront for fast delivery.
      • User Service:
        • Components: User DB.
        • Functionality:
          • User DB stores profiles, authentication, settings, and preferences.
        • Summary: Manages accounts, profiles, and settings with high transaction rates and complex user data queries.
      • News Feed Service:
        • Components: Redis Cache, News Feed DB, Cassandra DB.
        • Functionality:
          • Redis Cache for storing frequently accessed data.
          • News Feed DB aggregates and serves user timelines.
          • Cassandra DB offers scalable, high-availability NoSQL data storage.
        • Summary: Delivers personalized news feeds; Redis for caching, Cassandra for scalable data storage.
      • Social Service:
        • Components: SNS, Lambda, Social DB (Neo4j).
        • Functionality:
          • SNS for message delivery within pub/sub model.
          • Lambda for serverless event-driven code execution.
          • Neo4j, a graph DB, for complex social graphs and relationships.

          General Summary:

          • Instagram leverages microservices for modularity and scalability.
          • Each service is tailored for specific functionalities, enhancing fault tolerance.
          • Media, User, News Feed, and Social Services work together to provide a fast, reliable, and scalable platform
    Written by
    Rafael del Nero
    Join the discussion

    2 comments

    Stand Out as a Java Developer and Get Your Dream Job!

    You will get the book by email in a few minutes after registering.