Distributed Systems Explained

Distributed Systes

What is a Distributed System

In many scenarios, as a system grows, it might require a distributed approach to address the increased traffic of users.

A distributed system is a system that consists of multiple components that are located on different machines and communicate with each other by passing messages over a network

Despite the complexity, the demand for distributed systems keeps growing as the world becomes more interconnected; their usage rapidly increases because they allow for greater scalability and performance. Interestingly, many distributed computing techniques are inspired by real-world problem-solving strategies. To grasp these systems better, drawing parallels with everyday scenarios is beneficial.

Real-world Analogy

Starbucks Scale-out

The original Starbucks store in Seattle was a simple place.

Customers would enter, order a coffee from a barista, pay, and leave. This created a single-flow process that was easy to manage and efficient. Everything was located in one place, and everything happened synchronously.

As Starbucks grew, it began to add more complexity to its operations. The number of customers visiting the store increased, creating a natural need for a bigger store and more coffee machines, baristas, and seating places for a better and faster coffee serving process. Such an expansion would have required a significant investment of resources and time, negotiating lease agreements, and building or renovating the new store. Still, it is manageable and reasonable at this stage.

Vertical scaling

As the popularity kept growing with even more people sharing their experiences with the brand, there inevitably came a time when the newly renovated store could only serve some customers. The order queue grew, and the store needed help to meet the demand.

Ignoring all the hustle and bureaucracy, imagine that the owner opted to construct an even larger store with additional baristas, coffee machines, and seating. Doing this brain exercise, we inevitably will come to a point where making a bigger store economically is not viable or physically impossible to manage.

Going back to the 2000s, where a single server under your bed might have been enough to run a website, in today’s digital age, with explosive data growth and the ever-increasing demands of global users, this model is no longer feasible. The sheer volume of traffic, data processing needs, and expectations for near-instantaneous response times means that relying on a single, super-powered server is impractical and risky.

Moreover, with advancements in cloud technology, microservices, and containerization, the tech industry has shifted towards distributed systems prioritising flexibility, reliability, and scalability. In most cases, just as one wouldn’t expect a single coffee shop to serve an entire city, a single server can no longer cater to the digital needs of our interconnected global community.

Instead, distributed solutions, much like a chain of coffee shops, are designed to handle varying loads and demands, ensuring a consistent and optimized user experience across the board. This takes as to the next point.

Horizontal scaling

When it comes to practical situations such as a Starbucks store, it is apparent that there are constraints to expanding the store size and catering to customers worldwide. Even if a Starbucks store as large as Seattle were to be built and people from all over the world were to visit, handling the traffic in a single store would not be possible. In this example, it is easy to see that rather than attempting to construct a single Starbucks to handle increasing traffic and scale out in different geographical locations, the intuitive solution would be to build multiple stores across multiple streets, cities, and countries to serve customers independently and asynchronously.

This is known as horizontal scaling where you keep adding more nodes to a distributed system (= Starbucks store in our example) as the demand grows to handle the increased traffic. The advantage of this approach is that there is no limit to how many nodes you can add to the system, and the system can scale “infinitely”.

You can build more store in the crowded areas and fewer stores in the less crowded areas or add more nodes to the system that handles more traffic and fewer nodes to the system that handles less traffic.

While this sounds easy, the more stores you keep adding, the more complex the system becomes to ensure brand consistency across multiple stores and potentially in different countries and geographical locations in the world.

The same applies to the computing distributed systems. Any request that lands at any node should be treated similarly and output the same content across the system no matter where the end user is located.

Drawbacks of horizontal scaling

Horizontal scaling is a popular way to increase the capacity of a distributed system by adding more nodes. However, it also comes with some drawbacks, including:

  1. Increased complexity: As the number of nodes increases, the complexity of the system increases. This can make it more difficult to manage and maintain the system.
  2. Consistency: It can be more difficult to ensure that all nodes are consistent and output the same content. This is because each node may have its own copy of the data, and it can be difficult to keep all of the copies synchronized.
  3. Latency: The latency of the system can increase as the number of nodes increases. This is because it takes longer for messages to travel between nodes.
  4. Security: The security of the system can be more complex as the number of nodes increases. This is because there are more potential attack vectors.

Overall, horizontal scaling is a powerful tool that can be used to increase the capacity of a distributed system.

Netflix scaling to millions

Consider another example – Netflix.

Netflix began its journey as a DVD-by-mail service. As technology and user behaviours evolved, the company pivoted to become a leading internet streaming platform, offering digital content to viewers in over 190 countries. To guarantee high-quality and seamless viewing experiences, Netflix leverages Content Distribution Networks (CDNs ). These CDNs work in tandem with various Internet Service Providers (ISPs) to cache popular content closer to viewers. This means that instead of streaming every show or movie directly from a central Netflix server, viewers often receive content from a nearby server, reducing latency and buffering.

In essence, Netflix transitioned from physically mailing DVDs to strategically positioning digital content closer to global viewers. This distributed approach enables them to cater to millions of simultaneous users, allowing them to stream and watch movies and series with minimal interruptions. The shift from a physical delivery model to a digital one has allowed for more efficient logistics, better planning, and asynchronous content delivery.

As you can see, Netflix is distributed across the globe. That being said, there is a lot more to it than just having a bunch of servers in different locations, which allows a global reach. However, this is an excellent start to understand the concept of distributed systems.

Google Drive vast user base

The last example is Google Drive. Specifically, let’s examine the process of uploading and storing files for millions of customers.

Let’s delve into the mechanics of Google Drive, focusing on how it handles uploading and storing files for its vast user base.

Picture a vast storage facility accommodating items ranging from tiny trinkets to expansive furniture. If you’re stowing away just a few small things, it’s a straightforward process: place them inside, lock them up, and depart. But what happens when you have an entire household’s worth of goods? It’s impractical to move everything in one go. You could categorize items and maybe even disassemble bulkier pieces to maximize space.

Similarly, Google Drive processes file uploads based on their size. Files that are less than 5 MB in size are uploaded directly without any alterations. Larger files, however, are segmented into manageable chunks. Each chunk is then uploaded independently. Post-upload, Google Drive seamlessly reconstructs these chunks to form the original file. This chunking strategy aids in scalability. Distributing the chunks across different nodes ensures that each node handles a balanced amount of data, optimizing traffic and improving efficiency.

This approach allows Google Drive to scale to millions of users, handling many file sizes and types. Needless to say, this is a simplified explanation of how Google Drive works, but it is an excellent start to understanding the concept of distributed systems and how an analogy can help

Systems Simplified: Real-World Resonance

While this is not a guaranteed solution, in most cases, you can find a real-world analogy that will help your brain intuitively understand how to solve a problem optimally. You can then project it in your design solutions. In everyday life you can find examples of distributed systems everywhere. As an excercise, try to find a real-world analogy and analyze how it works and how it can be applied to a distributed computing systems.

Ultimately, this is quite a simple concept: you need to handle more user traffic - add more computers to the systems. The main problem is the problems that come with the system's distributed nature.

Next, we’ll slice and dice distributed systems into four main chunks . We’ll look closely at each piece so things get more straightforward. By breaking it down this way, we can better understand how everything in a distributed system clicks together, what problems we might encounter, and how to solve them.

Summary

Essentially, a distributed system ensures that more users can be served without compromising on performance. This design choice makes scaling a breeze, as one can simply add more nodes to accommodate a growing number of users. Think of it like Starbucks: as demand in a region grows, more outlets can be opened to cater to that specific demand.

A distributed system, when executed correctly, operates harmoniously, much like a well-oiled city mechanism. Each component, or node, functions in tandem with others to create an ecosystem where users – akin to city dwellers – benefit from seamless, consistent experiences. The beauty lies in the ability to scale, to adapt, and to ensure that no matter where a user is, they always feel right at home.

While distributed systems offer many advantages, such as scalability and fault tolerance, some systems may be better off remaining centralized for reasons such as security, performance, or simplicity. It is important to consider the pros and cons of distributed systems before deciding whether or not to use them in your application.