System Design

August 14, 2018 | 4 Minute Read

System Design interviews are less about getting lucky and more about actually doing the hard work of attaining knowledge. Performance in these interviews depends on the following 2 factors—

  • Your knowledge — gained either through studying or practical experience.
  • Your ability to articulate your thoughts.
  • When companies ask design questions, they want to evaluate your design skills and experience in designing large scale distributed systems
  • How well you do in such interviews often dictates hiring level/ salary.

Note: Most of the contents in this port are a compilation of the references.

Steps of system design—

  1. get a functional system first
    1. Requirement gathering, (Design twitter)
      • Who can post a tweet? (answer: any user)
      • Who can read the tweet? (answer: any user — as all tweets are public)
      • Will a tweet contain photos or videos (answer: for now, just photos)
      • Can a user follow another user? (answer: yes).
      • Can a user ‘like’ a tweet? (answer: yes).
      • What gets included in the user feed (answer: tweets from everyone whom you are following).
      • Is feed a list of tweets in chronological order? (answer: for now, yes).
      • Can a user search for tweets (answer: yes).
      • Are we designing the client/server interaction or backend architecture or both (answer: we want to understand the interaction between client/server but we will focus on how to scale the backend).
      • How many total users are there (answer: we expect to reach 200 Million users in the first year).
      • How many daily active users are there (100 million users sign-in everyday)
    2. System can be hypothetical, may consider basic functionalities. Say twitter dont need to support videos at this point.
  2. API/Functionality definition
    1. postTweet(uid, time, location, tweet…)
    2. celebTweet(uid, time, location, tweet…)
    3. generateTimeline(uid, time)
    4. recordLove(uid, tweet_id)
  3. Hardware/Resource requirement: Show ur interviewer you understand the scale
    1. Number of tweets/updates.
    2. Storage requirement
    3. Caching requirement
    4. Latency requirement, say we want the timeline to generate fast
    5. BW requirement
    6. Network IO
    7. Firewall
  4. Data Model
    1. User
    2. Tweet
    3. userFollows
    4. FavoriteTweets
  5. High level design: Generally we think this is the only thing that matters, unfortunately at comes at 5th position here.
    1. Draw high level system diagram
  6. Detailed component design
  7. Bottleneck identification and resolve
    1. Reduce Latency
    2. Queuing System, service discipline to select server
    3. Failure tolerance
    4. Bring in server on demand for scalability and increased load 

Scalability

  • Read is cheap write is expensive. 10ms for a disk seek.
  • Batch writes, for faster writing.
  • Writes –> disk seek. only 100seeks /second or 10ms per seek
  • Reads–> 250ns to read 1 MB
  • To learn more on these numbers Click Here

Design Patterns with examples

A simple design pattern example-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
MediaPlayer.java
public interface MediaPlayer {
 void play(String filename);
}

MediaPackage.java
public interface MediaPackage {
 void playFile(String filename);
}

Now, you can create the implementations classes :
MP3.java
public class MP3 implements MediaPlayer {
 @Override
 public void play(String filename) {
    System.out.println("Playing MP3 File " + filename);
 }
}

VLC.java
public class VLC implements MediaPackage {
 @Override
 public void playFile(String filename) {
    System.out.println("Playing VLC File " + filename);
 }
}

Funny guy TechLead on Design Patterns

Techlead Design Pattern

Simple twitter design

https://www.hiredintech.com/lecture_materials/twitter_problem_system_design.pngSimple twitter system design from HiredInTech.com

References:

  1. Anatomy of a system design interview.
  2. A compilation of lots of resources and systems.
  3. Numbers on scalability.
  4. Vending Machine w/ Design Pattern in Java.
  5. System Design Overall discussion.
  6. Uber-like ride sharing design.
  7. Grokking System Design Interview.