Home   programming  

Distributed system - explained with examples

Distributed systems are collections of independent computers that work together to appear as a single coherent system to the end-user. These systems allow multiple machines to collaborate to solve problems or provide services more efficiently and reliably than a single machine could.

Characteristics of Distributed Systems

  1. Resource Sharing: Components in a distributed system share resources, such as files, printers, or processing power.
  2. Concurrency: Multiple processes run concurrently on different machines.
  3. Scalability: Systems can scale horizontally (adding more machines) to handle increased load.
  4. Fault Tolerance: The system continues to operate even if some components fail.
  5. Transparency: Users perceive the system as a single entity, even though it consists of multiple machines.

Examples of Distributed Systems

  1. Internet: The most extensive distributed system, consisting of interconnected networks that allow data to be shared and accessed globally.
  2. Cloud Computing: Services like Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform distribute computing resources across multiple data centers worldwide.
  3. Microservices Architecture: An application architecture where a large application is divided into smaller, independent services that communicate over a network.
  4. Distributed Databases: Databases like Cassandra, MongoDB, and Google Spanner that store data across multiple machines to improve performance, availability, and reliability.
  5. Content Delivery Networks (CDNs): Networks like Akamai or Cloudflare that cache content on multiple servers worldwide to improve load times and reduce latency for users.

Real-World Examples

  1. Google Search: When you perform a Google search, the request is processed by multiple servers that quickly index and retrieve relevant information.
  2. Facebook: Facebook's infrastructure includes numerous servers that handle billions of user interactions daily, ensuring high availability and performance.
  3. Netflix: Netflix uses a distributed system to stream video content to users. They deploy their services across various data centers and use CDNs to deliver content efficiently.
  4. Bitcoin and Blockchain: The blockchain technology underlying cryptocurrencies like Bitcoin is a distributed ledger that records transactions across a network of computers.
  5. Online Multiplayer Games: Games like Fortnite or World of Warcraft run on distributed systems to manage game state, player interactions, and real-time updates.

Advantages of Distributed Systems

  1. Scalability: Easily add more machines to handle increased load.
  2. Reliability and Availability: Redundancy and fault tolerance ensure that the system remains operational even if some components fail.
  3. Performance: Distributed systems can process tasks in parallel, reducing processing time.
  4. Resource Sharing: Efficiently utilize resources spread across multiple machines.

Challenges of Distributed Systems

  1. Complexity: Designing and managing distributed systems is more complex than single-system architectures.
  2. Security: Ensuring security across multiple machines and networks can be challenging.
  3. Consistency: Maintaining data consistency across distributed databases can be difficult.
  4. Latency: Network latency can affect performance, especially in systems that require real-time processing.

Example of a Simple Distributed System

Let's consider a simple distributed web application consisting of:

  1. Frontend Service: Serves the user interface.
  2. Backend Service: Handles business logic.
  3. Database Service: Stores user data.

Each service runs on a different server and communicates over a network.

Frontend Service (HTML + JavaScript):

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Distributed App</title>
        async function fetchData() {
            const response = await fetch('http://backend-service/data');
            const data = await response.json();
            document.getElementById('data').innerText = JSON.stringify(data);
    <h1>Distributed App</h1>
    <button onclick="fetchData()">Fetch Data</button>
    <pre id="data"></pre>

Backend Service (Node.js + Express):

const express = require('express');
const app = express();
const port = 3000;

app.get('/data', (req, res) => {
    res.json({ message: 'Hello from the backend service!' });

app.listen(port, () => {
    console.log(`Backend service listening at http://localhost:${port}`);

Database Service (Simulated with a JSON file):

    "users": [
        { "id": 1, "name": "Alice" },
        { "id": 2, "name": "Bob" }

In this example, the frontend service sends a request to the backend service to fetch data. The backend service processes the request and responds with data, possibly retrieving it from the database service. This simple setup demonstrates the basic principles of a distributed system where different components run on separate machines and communicate over a network.

Published on: Jul 04, 2024, 11:23 AM  


Add your comment