Preparation Roadmap for LLD Interviews

This is a 7-Day plan to help you prepare
for Low Level Design Interviews using
common design patterns.

Languages: As of now Java and Python are supported.



We won't be covering every detail of large systems
like Parking Lot or Food Ordering apps with
hundreds of components and classes.


1. Instead we will deep dive into the
   core features of questions which interviewers
   expect to discuss with you in a LLD interview

2. YouTube video solutions will also teach you how to
   explain your solution to the interviewer step by step.
YouTube Video Thumbnail
Link



YouTube Video Thumbnail
Link


YouTube Video Thumbnail
Link
How to Crack Low-Level Design Interviews?

Here are the four things you need to learn,
to crack a low level design interview round.


1. How to specify core features of the question
2. How to break your solution in multiple classes
3. Usage of design patterns to solve the problem
4. How you handle multithreading (optional sometimes)


Plan is to start each day with a few short videos to get you in preparation mode,
and then do one coding question covering one or more design patterns.


There are two types of low level design interview formats:
1. 75 to 90 minutes of machine Coding
2. 45-60 minutes of face to face discussion

Watch the Youtube Video on the right for details.
YouTube Video Thumbnail
Link
YouTube Video Thumbnail
Link
YouTube Video Thumbnail
Link
YouTube Video Thumbnail
Link
Try to complete Coding for questions even if
you have to watch the solution multiple times,
because that will make you comfortable with
different data structures especially
thread safe data structures and synchronization.
This will be useful when interviewer tweaks the question.



These are the four most common design patterns asked in LLD interviews.
Strategy, Observer, Factory, and Singleton
We will practice them first and then move on to other design patterns.


Practice Problem
Design a Parking Lot
https://codezym.com/question/1

Parking Lot design is sort of the Hello World of low level design questions.
Most people start their LLD interview preparation with this question.

Python solution video on the right takes you through the core features
like park, remove vehicle, search vehicle and also teaches you
how to clearly explain your design to interviewer step by step
in a 45-60 minute LLD interview.

For Java , we have to implement our solution for a multi-threaded
environment using locking and thread safe data structures.
Video on the right show a simple solution using synchronized keyword
which is the popular locking mechanism in Java.

However, using synchronized or any other lock is simple but not efficient
as it locks out other threads from doing write operations
concurrently.


YouTube Video Thumbnail
Link

YouTube Video Thumbnail
Link
YouTube Video Thumbnail
Link
Video on the left shows a more efficient solution using a thread safe list
ConcurrentLinkedDeque to store free spots on each floor.
It ensures that on each floor rather than using brute force
to find a free spot, we can add/remove parking spots in O(1)

Strategy Design Pattern

Strategy Pattern is used when we need different algorithms
for the same functionality. Some examples are :
1. Different moves in chess: straight, diagonal, 2+1 move
2. different ways to order list of items e.g. by price, rating, most ordered etc
YouTube Video Thumbnail
Link
YouTube Video Thumbnail
Link


Practice Problem
Design a Parking Lot using Strategy Pattern
https://codezym.com/question/7

We revisit the Parking Lot design again.
However, in this question we have to implement
two different parking strategies,

So you should use strategy pattern here.

Python solution video on the right takes you
through the core features like
park, remove vehicle, search vehicle and it also
teaches you how to clearly explain your design
to interviewer step by step
in a 45-60 minute LLD interview.

Python video has slightly better explanation
than the Java video below it.

YouTube Video Thumbnail
Link


YouTube Video Thumbnail
Link

Observer Design Pattern

Observer Pattern is a behavioural design pattern and
it is used when you want to have loose coupling
between data which is getting changed and
multiple views or observers which need to receive the changes.

example: Giving 1 to 5 star rating to a product on ecommerce website
needs to be observed by the class which shows list of top rated products.

Observer pattern is generally used along with strategy pattern
to inform different strategy classes about
changes occurring in the common data structure.

example: a customer support system may have different strategy classes
to assign an agent to a customer support call.
Also each strategy need to be informed whenever
an agent is assigned a case so that they can decide
whether to assign new cases to this agent or not.
Observer pattern will be used in this case.

YouTube Video Thumbnail
Link


YouTube Video Thumbnail
Link

Practice Problem
Design a food ordering and rating system like
  Zomato, Swiggy, DoorDash
https://codezym.com/question/5

This system will have functionality to order food, rate orders
and list top restaurants based on their rating

Now whenever an order is rated then it has to observed
by classes which return top restaurants lists based on their rating.
So this is an ideal use case for observer design pattern

Watch Java and Python video solutions on the right for explanation.

YouTube Video Thumbnail
Link
   
YouTube Video Thumbnail
Link

Factory Design Pattern

Factory Pattern is a creational design pattern and
it is used to decouple object's creation logic from their usage.
This is required when we may have to create similar objects
which follow the same interface or are subclasses of same superclass

Some example are :
- Creating different pieces in chess e.g. pawn, king, queen etc.
- Creating different type of cars in a car race video game.
YouTube Video Thumbnail
Link
YouTube Video Thumbnail
Link

YouTube Video Thumbnail
Link
YouTube Video Thumbnail
Link
Singleton Design Pattern

Singleton Pattern is used when we need a
single instance of an object.
e.g. A connection pool manager for managing
database connection will be a singleton.
Generally factories are implemented as a singleton

Practice Problem
Design Chess Game
https://codezym.com/question/8

In Low Level Design of chess we use following design patterns
1. Chess Piece Factory to create different
chess piece objects like king, queen, pawn etc

2. Strategy pattern to implement different moves
e.g. straight move, diagonal move etc.

3. Singleton pattern to ensure there is a
single instance of chess piece factory object.
Actually this question also serves as a counter example
as to where we should not use singleton pattern.

Even though we need only once instance of Chess Piece Factory
but it is being used from only one place as you will see in solution videos.
So making ChessPieceFactory a singleton is unnecessary in this case.



YouTube Video Thumbnail
Link

YouTube Video Thumbnail
Link

Flyweight Design Pattern

Flyweight design pattern is used when we need to
create a large number of similar objects
It helps us save memory space by sharing
constant state among objects.

  Some examples are
- Sharing 3-d images of thousands of soldiers
  in a computer war game
- Sharing styles of characters in a text editor
  like Microsoft word.
YouTube Video Thumbnail
Link
YouTube Video Thumbnail
Link

Practice Problem
Design a Text Editor/Word Processor like Microsoft Word
https://codezym.com/question/9

In a text editor, each character can have a different style
in terms of parameter like colour, font size etc

Also there can be millions of characters in a text editor file,
but total number of different styles used will be just from
a few 100's to a few 1000's

So it makes sense to share character style as constant intrinsic state
and reduce memory footprint of program
YouTube Video Thumbnail
Link

YouTube Video Thumbnail
Link

State Design Pattern

State is a behavioural design pattern and it is used when
an object has to change its behaviour as its internal state changes.

For example an ATM machine may be in different states
like idle, money withdrawal in progress, validating pin etc
and will respond to keyboard button presses differently in each state.
The same keyboard can be used to input user's PIN as well as
mobile number, depending on the current state of ATM.

another example is of a Cab booking System
Ride can be in states like:
Ride Requested, Ongoing, Finished, Cancelled
which will have multiple states and in each of these states
calculation for a common behaviour like
timeTakenToReachDestaination() will be different.

YouTube Video Thumbnail
Link

YouTube Video Thumbnail
Link

Practice Problem
Design an elevator management System with multiple lifts
https://codezym.com/question/11

A lift in an elevator system can be in one of three states.
Moving Up, Moving Down and Idle
And in each state it will behave differently in taking decisions like
whether to stop on a floor, add a new request or not etc

So we will use state design pattern to solve this problem.

YouTube Video Thumbnail
Link

YouTube Video Thumbnail
Link

Multi-Threading

In LLD interviews, after design patterns, discussion moves on to multi-threading.
For these question you have to use synchronization, locks and thread safe data structures.

If you are using Java then you have access to thread safe data structures
like AtomicInteger, ConcurrentHashMap, ConcurrentLinkedDequeue etc.

Practice Problem
4. Design an order and inventory management system https://codezym.com/question/4
An inventory management system of a
simple e-commerce platform,
needs to have the capability of
handling sellers, products and orders.
Inventory is number of items of a
particular product in a seller's warehouse.
   


YouTube Video Thumbnail
Link




YouTube Video Thumbnail
Link
   
3. Design a customer issue resolution system https://codezym.com/question/3
Customer support is nothing but a group of agents
with skills for solving a set of issues.

Customer Issues can be classified into multiple types
like order delayed, Payment Related etc.
A customer issue resolution system is used to
assign customer's issues to agents.




Best of Luck