There are 3 main categories of load balancers:

- DNS based
- transport layer (L4)
- application layer (L7)

This how they work and their differences: {1/12} ↓
Load balancers are a fundamental part of every distributed architecture.

They essentially balance the clients requests between a pool of servers.

But they can have more functionalities according to their category.

{2/12}
1. DNS load balancers

The idea is to add the public ip address of the servers to the application's DNS record.

The clients can than pick up one of the addresses during the DNS resolution process.

Usually the choose of the address is made using a round robin strategy.

{3/12}
This is probably the simplest way of implementing a load balancer, but it has some drawbacks.

The main one is that it's not resilient to failures.

If one of the servers gets unavailable, the DNS server continue to provide its IP address.

{4/12}
Even removing the IP address of the failed server from the DNS record won't be effective.

The change needs time to propagate since the DNS entries are usually cached.

This is why DNS load balancing is mostly used in practice to distribute traffic among data centers.

{5/12}
2. Tranport layer load balancers (L4)

These load balancers work at TCP level of the network stack.

The idea is to map physical network cards to multiple virtual ip addresses.

Each virtual ip address (VIP) is associated to a pool of servers.

{6/12}
When a client establishes a TCP connection to a VIP, the load balancer picks a server from the pool.

All the traffic between the client and the server flows through that connection.

The load balancer takes care of translating the VIPs to the servers's addresses.

{7/12}
The advantages of using a L4 load balancer are that it is fast and very flexible.

The drawback is that can only redirect bytes without knowing their actual meaning.

So it can't support high level features like terminating TLS connections.

{8/12}
3. Application level load balancer (L7)

These load balancers act as HTTP reverse proxies.

They check HTTP requests received from a client and send them to a server picked from a pool.

They handle 2 TCP connections, one with the client and another with the server.

{9/12}
L7 load balancers are powerful and can do many things like:

- demultiplex HTTP requests sharing the same TCP connection

- rate limiting request according to the HTTP header

- route HTTP requests belonging to a logical session to the same server using cookies

{10/12}
Their main drawback is that they have lower throughput respect to L4 load balancers.

This makes them more vulnerable to DDOS attack.

Moreover all the traffic direct to an application goes through the load balancer, making it potentially a single point of failure.

{11/12}
A last side note. These categories of load balancers are not mutually exclusive.

It's not uncommon to see companies using both L4 and L7 load balancers.

Usually the L4 load balancers are placed before the L7 load balancers.

{12/12}
Thanks for taking the time to read!

If you liked it, I'd be grateful if you'd:

• leave a like or retweet the first tweet

• follow @franc0fernand0 for more distributed system content

• subscribe my new newsletter (link in bio)

Your support encourages me to keep writing!

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Fernando 🇮🇹🇨🇭

Fernando 🇮🇹🇨🇭 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Franc0Fernand0

Oct 29
Redis is commonly known as a key-value server, but actually is also a messaging server.

This is how Redis Pub/Sub works and when it's a good choice: {1/10} ↓
Redis Pub/Sub uses a data type called channel to support publish and subscribe operations.

A client can subscribe to multiple channels and a channel can have 0 or multiple subscribers.

When new content is published on a channel, Redis push it out to the subscribers.

{2/10}
Publishers and subscribers are loosely coupled because they interact only through channels.

Redis uses an at-most-once delivery semantic to send messages to the subscribers.

This means that only (and all) currently connected subscribers get the messages.

{3/10}
Read 11 tweets
Oct 26
The 2 pointers method is a common technique used in coding interviews and programming.

This is how it works: {1/5} ↓ Image
The key idea is to have 2 pointers (i.e. 2 indexes) moving through an array.

Each pointer moves in one direction only, ensuring the method is efficient.

Let's consider an example where we have an array of n positive integers and a target sum t.

{2/5}
The goal is to find if a subarray whose sum is x exists.

For this problem, the pointers identify a subarray's first and last value.

On each step, the left pointer moves one position to the right.

{3/5}
Read 6 tweets
Oct 1
Push notifications are a very popular feature for many applications.

This is how to design a scalable push notification service: ↓ {1/13}
Push notification services are usually based on a publish/subscribe model.

Clients subscribe to different information channels or topics.

When new content is available on a channel, the servers push that information out to the clients.

{2/13}
At high level a push notification service works as follow:

1. Back-end applications (on-premises or cloud) configure the service to send notifications

2. At start-up the client applications (mobile or web browser) subscribe to a topic

{3/13}
Read 14 tweets
Sep 10
I recently went again through "Master the Code Review", a course by @curtiseinsmann

I got many great insights on how to get better at code reviews as both author and reviewer.

Here I share my 9 main takeaways: ↓
@curtiseinsmann 1. A code review process should fix clear expectation for authors and reviewers.

Authors should carefully prepare a description and choose reviewers familiar with the code.

Reviewers should show ownership and responsibility, being kind and thorough while writing the comments.
@curtiseinsmann 2. Reviewers needs clearly to look for flaws inside the diff like missed edge cases or possible optimizations.

But they need also to look for flaws outside the diff like:

• side effects on other part of the system
• not backwards compatible changes
• partial refactoring
Read 11 tweets
Aug 6
Microservices are not necessarily better than monoliths.

Using microservices can be a good choice or not depending on the specific use case.

The 6 main factors to take into account: ↓
1. Coupling

Microservices can be a reasonable choice only when they are loosely coupled.

Otherwise they end up being ugly not mantainable distributed monoliths.

Common reasons of coupling are poor APIs or libraries that need to be updated in lock step to multiple services.
2. Technology stack

In theory each microservice can use a different tech stack, but this has some cons.

First, having different tech stacks can be an obstacle for developers to change team.

Second, providing cross service functionalities and libraries can be more difficult.
Read 7 tweets
Jul 30
Sometimes in distributed systems a node needs to act has a leader with special powers like:

- accessing shared resources
- assigning work to other nodes
- taking care of write operations

Raft is a popular algorithm to elect a leader.

How does it work ?

//Thread// ↓ {1/9}
Electing a leader in a distributed environment is not a trivial task.

Indeed a good leader election algorithm needs to have 2 features:

1. safety: at most one leader shall be active

2. liveness: a leader shall be elected even if failures occurr

{2/9}
Raft is a leader election algorithm that guarantees these properties.

It makes 2 assumptions.

The 1st one is that time is divided into slots of arbitrary length called election terms.

Terms are numbered using logical timestamps (e.g. consecutive integers).

{3/9}
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(