Info #

Lecture notes

Lecture #

LLD is concerned about how we can write better code. This means code that is extensible (new features), reusable, maintainable (bug fixes).

System design (HLD) is the study of how different infrastructure layers that work together to server an application at a scale at a desired efficiency. Example of infrastructure layers: LB, App servers, database servers.

We are not going to cover (and it’s usually not discussed in interviews):

  1. Knowledge - won’t cover tangible steps like setting up libraries, components etc. This is because the focus here is on logical design, not implementation. Whats the best library? Whats the best language
  2. HLD is about problem solving (i.e. ability to make good decisions).
  3. No implementation.
  4. The output artifact here is a diagram, flow-chart etc.
  5. The main thing in interviews and day-to-day jobs is to have an intriguing and useful discussion.

Why do we need distributed systems? #

Q: Why do we even need distributed system? Why don’t very simple and intuitive design work? A: He gives a website “deli.cio.us”, a website from 2003 that did webpage bookmarking. He first explains how you need to purchase too things, a static IP address (from ICANN, or AWS) and a domain name (from a domain registrar like GoDaddy, Namecheap). Then you add the static IP address in the domain registrars setting, causing the domain-ip pair to be copied to DNSs around the world. This way, your website becomes accessible to outside users. But majorly, he discusses that due to a large number of users (i.e. high load), a single machine is actually a single-point-of-failure (SPOF) which is highly undesirable. The fact that singular machines cannot handle high-load and also are SPOFs necessitates the need for complex and distributed systems.

So suppose the developer of this site created the website/server and running it on his laptop, how will they get incoming requests? Lets solve this problem (below).

Ability to receive internet requests on local machine - NAT (extra info) #

Suppose you developed a website and are running it on your laptop. Is it possible for this app to get requests from an outside server?

ISP’s usually maintain machines running software that’s usually called a NAT. It is able to create a full network (say 232 private addresses) with just one actual IP address (from ICANN).

Ok, now the site would get incoming requests.

Lets solve these connected-problems (below).

Load balancers #

The simplest way to avoid SPOF is to have multiple app server machines, and add an extra machine called load balancer whose only job is to receive a user request and forward it to one of the app servers. The app server does the work, and responds to the user via the load balancer.

The setup flow is simple: the LB is switched on first. Then we switch on the app servers, and each of them sends a “register” request to the LB. The LB maintains a list of app servers. Note that only the LB needs to have a static IP address, and app servers can have private/virtual addresses (since they don’t talk directly to the outside world).

Algorithms for distributing load equitably (or LB choosing the most appropriate server to forward a request too):

Is-alive mechanisms used by LBs:

Summary #

Assignments #

None listed.