System Design

System design is the process of defining the architecture, components, modules, interfaces, and data for a system to satisfy specified requirements. It involves translating user requirements into a detailed blueprint that guides the implementation phase. The goal is to create a well-organized and efficient structure that meets the intended purpose while considering factors like scalability, maintainability, and performance.

An effective system design interview gives strong signals about a person’s ability to collabrate, to work under pressure, and to resolve ambiguity constructively.

fundamentals

  • load balancing
  • api gateway
  • distributed systems
  • DNS
  • caching
  • CDN
  • data partitioning
  • proxies
  • redundancy and replication
  • CAP & PACELC theorems
  • Databases (SQL, NoSQL)
  • indexes
  • bloom filters
  • long-polling, websockets, server-sent events
  • quorum
  • heartbeat
  • checksum
  • learder and follower
  • distributed messaging system

Components of a System

  • load balancers
  • KV stores
  • blob storage
  • databases
  • rate limiters
  • monitoring systems
  • distributed system messaging queue
  • distributed unique id generator
  • distributed search
  • distributed logging services
  • distributed task scheduler

Design Interview Framework Flow

  1. understand the requirements
  2. identify the major components
  3. choose appriopriate technology
  4. define the interface
  5. design the data model
  6. consider scalability and performance
  7. test and validate the design
  8. deploy and maintain the system

Gather Requirements

To test your ability to clarify an open-ended and ambiguous problem.

interviewers do look for solid product sense and strong user empathy.

  1. who is it for, and why do we need to build it?
  2. what are the features we need to solve the users’ problem?

  • scale
    • QPS
    • Storage
  • performance constraints
  • accurancy requirements

what the interviewers looks for and what they don’t

do

  1. a broad, base-level understanding of system design fundamentals
  2. back-and-forth about problem constraints and parameters
  3. well-reasoned, qualified decisions based on engineering trade-offs
  4. the unique direction your experience and decisions take them
  5. a holistic view of a system and its users

don’t

  1. deep expertise in the given problem domain
  2. assumptions about the prompt
  3. specific answers with ironcald certainty
  4. a predefined path from the beginning to end of the problem
  5. strictly technical considerations

general rules of thumb

  • if the interviewer interrupts you, it’s probably because you’re going off track
    • it’s fine if the interviewer asks you questions, but it’s bad sign if the interviewer starts telling you how to do things
  • It’s more important to cover everything broadly than it is to explain every small thing in detail.
  • What makes these questions difficult or complicated is not the fact that they are inherently complicated. It’s because the interviewer intentionally chooses to withhold information. Information that you can only get if you ask the right questions.
  • During requirements gathering… if your interviewer says something that seems random, you’ll surely need to use it.
  • Whenever there is user-generated code execution involved (aka low trust code), running it in isolation should be a non-functional security requirement.
  • Assess your current solution, provide your opinion, and then ask your interviewer for their thoughts. This is the best way to iterate on system design.
  • When looking to optimize performance for a read-heavy access pattern that requires several queries, consider storing the final result in a separate table and keeping it up to date.

functional requirements

  • identify the main objects and their relations
  • what information do these objects hold? are they mutable?
  • think about access patterns. “Given object X, return all related objects Y”. consider the cross product of all related objects.
  • list all requirements you’ve identified and validate with your interviewer
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## design tiktok

### objects and relations

- account -> video
  - can post
  - can like
  - can comment
- account -> account
  - can follow

### mutability

once a video is uploaded it will stay immutable

### access patterns

- given a user, get all videos they posted
- given a user, get their feed
- given a video, get likes/comments
- post a video
- follow an account
- like/comment on a video

non-functional requirements

  • performance
  • availability
  • security

AI contents

TikTok

Designing a platform like TikTok requires careful consideration of various components and architectural decisions. Here’s a high-level overview of how you could design a TikTok-like application:

  1. User Management:

    • Create a user authentication and authorization system using industry-standard practices like JWT (JSON Web Tokens) or OAuth.
    • Allow users to sign up, log in, and manage their profiles, including profile pictures, bios, and personal information.
  2. Video Upload and Storage:

    • Implement a reliable and scalable system for video uploads, which may involve using cloud storage services like Amazon S3 or Google Cloud Storage.
    • Consider implementing a content delivery network (CDN) to serve videos efficiently to users across different geographical locations.
    • Design a system to handle video processing and compression to optimize for different devices and network conditions.
  3. Video Feed:

    • Develop a recommendation engine to curate personalized video feeds for users based on their interests, interactions, and viewing history.
    • Implement algorithms to rank and sort videos based on various factors like view count, engagement, recency, and relevance.
    • Consider using machine learning techniques to improve content recommendations over time.
  4. Social Features:

    • Enable users to follow other users, like and comment on videos, and share videos with friends or on other social platforms.
    • Implement a notification system to inform users about new followers, likes, comments, and other relevant activities.
    • Consider adding features like direct messaging, live streaming, and video duets/reactions.
  5. Content Moderation:

    • Develop a robust content moderation system to filter out inappropriate, offensive, or illegal content.
    • Implement automated moderation tools and mechanisms for user reporting to flag harmful content.
    • Define clear community guidelines and enforce them consistently.
  6. Analytics and Metrics:

    • Integrate analytics tools to track user engagement, video performance, and other key metrics.
    • Collect and analyze data to gain insights into user behavior, content preferences, and platform performance.
    • Use these insights to optimize the platform, improve recommendations, and drive product decisions.
  7. Scalability and Performance:

    • Design the application with scalability in mind from the beginning, considering factors like load balancing, caching, and horizontal scaling.
    • Implement techniques like sharding and partitioning to handle large amounts of data and traffic.
    • Continuously monitor and optimize performance by identifying and addressing bottlenecks.
  8. Security and Privacy:

    • Implement industry-standard security practices, such as data encryption, secure communication protocols (HTTPS), and regular security audits.
    • Comply with relevant data privacy regulations (e.g., GDPR, CCPA) and provide users with control over their data and privacy settings.
    • Implement measures to prevent abuse, such as rate limiting, IP blocking, and bot detection.
  9. Infrastructure and DevOps:

    • Utilize cloud computing platforms like AWS, Google Cloud, or Microsoft Azure for infrastructure provisioning and management.
    • Implement continuous integration and continuous deployment (CI/CD) pipelines for efficient software delivery.
    • Leverage containerization technologies like Docker and orchestration tools like Kubernetes for easier deployment and scaling.
  10. Third-Party Integrations:

    • Consider integrating with third-party services like social media platforms, advertising networks, and analytics tools to enhance functionality and monetization opportunities.
    • Provide APIs and developer tools to enable third-party developers to build applications or integrations on top of your platform.

This is a high-level overview, and the actual implementation would involve many more detailed components and architectural decisions. It’s crucial to consider factors like scalability, performance, security, and user experience throughout the design and development process.

Notion

Designing a product like Notion, which is a versatile workspace and collaboration tool, requires a comprehensive approach that encompasses various components and features. Here’s an overview of how you could design a Notion-like product:

  1. User Management and Authentication:

    • Implement a secure user authentication system, allowing users to sign up, log in, and manage their accounts.
    • Consider integrating with third-party authentication providers like Google, Apple, or GitHub for seamless sign-in experiences.
  2. Workspace and Content Management:

    • Design a hierarchical structure for organizing workspaces, projects, and pages, similar to Notion’s nested pages and sub-pages.
    • Implement a rich text editor with support for formatting, embedding media (images, videos, code snippets), and real-time collaborative editing.
    • Enable users to create different types of content blocks, such as lists, tables, kanban boards, calendars, and databases.
    • Provide version control and revision history for tracking changes made to content.
  3. Database and Data Modeling:

    • Design a flexible and scalable database schema to store and manage various types of data, including structured and unstructured data.
    • Implement a robust data modeling system that allows users to define custom data types, properties, and relationships between different content blocks.
  4. Search and Navigation:

    • Develop a powerful search engine that allows users to search across their workspaces, pages, and content blocks based on keywords, tags, and other metadata.
    • Implement intuitive navigation and browsing mechanisms, such as breadcrumbs, favorites, and recently accessed items.
  5. Collaboration and Sharing:

    • Enable real-time collaboration, where multiple users can simultaneously edit and collaborate on the same content.
    • Implement access control and permissions management, allowing users to share workspaces, projects, or individual pages with specific collaborators or teams.
    • Provide commenting and annotation features for facilitating discussions and feedback.
  6. Templates and Automation:

    • Create a library of pre-built templates for different use cases, such as project management, task tracking, documentation, and knowledge bases.
    • Implement automation and workflow capabilities, allowing users to create custom workflows, triggers, and actions based on specific conditions or events.
  7. Integrations and API:

    • Develop a robust API that allows third-party applications and services to integrate with your product, enabling data exchange and custom workflows.
    • Consider integrating with popular productivity tools, communication platforms, and cloud storage services.
  8. User Interface and Experience:

    • Design an intuitive and responsive user interface that adapts to different devices and screen sizes.
    • Implement features like drag-and-drop, keyboard shortcuts, and customizable views to enhance user productivity and personalization.
  9. Security and Privacy:

    • Implement industry-standard security practices, such as data encryption, secure communication protocols, and regular security audits.
    • Comply with relevant data privacy regulations and provide users with control over their data and privacy settings.
  10. Scalability and Performance:

    • Design the application with scalability in mind from the beginning, considering factors like load balancing, caching, and horizontal scaling.
    • Implement techniques like sharding and partitioning to handle large amounts of data and traffic.
    • Continuously monitor and optimize performance by identifying and addressing bottlenecks.
  11. Analytics and Insights:

    • Collect and analyze user data to gain insights into usage patterns, feature adoption, and areas for improvement.
    • Provide users with analytics and reporting capabilities to track their productivity, team collaboration, and project progress.

This is a high-level overview, and the actual implementation would involve many more detailed components and architectural decisions. It’s crucial to consider factors like scalability, performance, security, and user experience throughout the design and development process. Additionally, you may want to prioritize and iteratively develop features based on user feedback and market demands.

system design interview

tips and frameworks

4-steps process

  1. understand the problem and establish design scope
  2. propose high-level design and get buy-in
  3. design deep dive
  4. wrap up

do:

  • always ask for clarification. do not assume your assumption is correct
  • understand the requirements of the problem
  • there is neither the right nor the best answer. a solution designed to solve the problems of a young startup is different from that of an established company with millions of users
  • let the interviewer konw what you are thinking. communicate with your interview
  • suggest multiple approaches if possible
  • once you agree with your interviewer on the blueprint, go into details on each component. design the most critical components first
  • bounce ideas off the interviewer. a good interviewer works with you as a teammate
  • never give up

don’ts

  • don’t be unprepared for typical interview questions
  • don’t jump into a solution without clarifying the requirements and assumptions
  • don’t go into too much detail on a single component in the beginning. give the high level design first then drill down
  • if you get stuck, don’t heisitate to ask for hints
  • don’t think in silence
  • don’t think your interview is done once you give the design. you are not done untile your interviewer says you are done. ask for feedback early and often

online examples

References

Licensed under CC BY-NC-SA 4.0
Get Things Done
Built with Hugo
Theme Stack designed by Jimmy