DEV Community

Cover image for System Design | API, DB, CN, Load Balancer....
Shubham Tiwari
Shubham Tiwari

Posted on • Edited on

System Design | API, DB, CN, Load Balancer....

Hello everyone, today, i will be briefing some system design concepts which you might know to understand how things work on the internet.

Let's get started...

Table of content

Computer architecture

  • To store data, we have disk storage and it is non-volatile, it contains OS applications and user files. SSD gives faster retrivals than HDD.

  • RAM - It allows to quick read and write access to data structures, variables, and application data. It is a volatile memory. Read write could surpass 5000mbps

  • Cache - It is smaller than RAM but read write access is in nano seconds and faster than RAM. We store frequently used data

  • CPU - Brain of the computer, it fetches, decode and process the information. It executes the machine code which is provided by a compiler.

Production App Architecture

  • CI/CD - This ensures that our code goes to the remote repo with some quality and pipeline checks and then goes to the production without any manual work.

  • Load balancers - These split the traffic and send it on multiple instances on the server to reduce the load on single instance and make the smooth network requests/response.

  • Logging and Monitoring - To store every micro interactions, checking data and logs, which could be used to debug the code for any bug or error. Sentry could be used for the error or bug detections.

  • A good design system has scalibility, maintainability, effeciency and reliability.

  • 3 key points of system design - moving data, storing data and transforming data.

  • Throughput - How much data our system could handle over a period of time.

  • Latency - How long it takes to handle a request.

Networking Basics

  • IP Address - When two computers communicates with each other with data packets having IP address to ensure that the data packet has reached the right destination. It could be static or dynamic.

  • TCP ensures reliable communication and nothing is missing in the package.

  • UDP is less reliable but faster than TCP and usually used in live communication.

  • DNS is a name assigned to each IP address.

Application Layers

  • HTTP - It is a protocol for communication with no memory and does not do anything in DB.

  • HTTP Method - GET(Getting data), POST(Saving data), PUT(Updating data) and DELETE(Deleting data.

  • SMPT - Email transmission across the internet, it is a protocol for sending emails.

  • IMAP - Used to retrieve emails from the server.

  • POP3 - Used to download emails from the server.

  • FTP - Files transfer over the internet.

  • SSH - For command login or transferring files.

  • WebRTC - Enables browser to browser application for voice call, video chat, and file sharing.

API

  • CRUD stands for Create(POST), Read(GET), Update(POST OR PATCH) and Delete(DELETE).

  • REST is a stateless api using standard HTTP methods, uses JSON for data exchange

  • GraphQL is strongly typed schema based queries, avoids over and under fetching of data but queries can impact server performance.

  • gRPC is efficient, built on HTTP/2, user protocol buffer, mulltiplexing and server push but less human readable.

  • CORS - Cross origin resource sharing as the name suggests it controls which domains are allowed to access your API.

  • Caching is used to improve the performance and eficiency of system. It stores a copy of data on a temporary storage for faster access. We could control how long a cache should be there and expire.

  • CDN - these are servers set on different geographical locations to serve the content faster to the nearby users, reducing the load on origin server. it also has reduced latency, high availability and improved security.

Proxy Server

A proxy server acts as an agent or intermediary for the user, passing through all Web requests and responses

1) Forward Proxy

A forward proxy sits in front of clients and forwards requests from many clients to a server. It's typically used for caching, filtering, and logging.

Scenario: An organization uses a forward proxy to allow employees to access the internet. The proxy can cache frequently accessed web pages, filter out unwanted content, and log web activity for security purposes.

2) Reverse Proxy

A reverse proxy sits in front of servers and forwards requests from clients to the appropriate server. It’s often used for load balancing, security, and caching.

Scenario: A company’s website receives a high volume of traffic. A reverse proxy distributes incoming requests across multiple web servers to ensure no single server becomes overwhelmed, improving performance and reliability.

3) Open Proxy

An open proxy is accessible by any user on the internet. They can be used for anonymity but are often insecure and can be exploited for malicious activities.

Scenario: A user wanting to browse the internet anonymously uses an open proxy server. However, these proxies are often unreliable and can expose the user to security risks.

4) Transparent Proxy

A transparent proxy does not modify the request or response beyond what is required for proxy authentication and identification. The client is unaware of the proxy's existence.

Scenario: A coffee shop offers free Wi-Fi and routes all internet traffic through a transparent proxy. The proxy enforces content filtering policies without the users knowing that their requests are being proxied.

5) Anonymous Proxy

An anonymous proxy hides the user's IP address but identifies itself as a proxy server. It provides some level of anonymity without concealing the fact that it is a proxy.

Scenario: A user accesses a website through an anonymous proxy to hide their IP address from the website. The website knows that a proxy is being used but cannot determine the user's actual IP address.

6) Distorting Proxy

A distorting proxy identifies itself as a proxy server but presents a false IP address to the target server.

Scenario: A user wants to bypass geo-restrictions on a video streaming site. They use a distorting proxy that shows a different IP address to the streaming service, tricking it into thinking the user is in a different location.

7) High Anonymity Proxy (Elite Proxy)

A high anonymity proxy does not identify itself as a proxy and does not reveal the user’s IP address. It offers the highest level of anonymity.

Scenario: A journalist working on a sensitive investigation uses a high anonymity proxy to ensure their online activities cannot be traced back to them, providing maximum privacy and security.

Load Balancer

A load balancer is a device or software that distributes incoming network traffic across multiple servers to ensure no single server becomes overwhelmed. This helps to improve the availability, reliability, and performance of applications or websites by balancing the load among multiple resources. We should be monitoring the health check of the load balancer and could have auto or self healing automation.

Common Load Balancing Algorithms:

Round Robin: Distributes requests sequentially across the servers.

  • Least Connections: Sends requests to the server with the fewest active connections.

  • IP Hash: Distributes requests based on the client’s IP address, ensuring requests from the same client go to the same server.

  • Weighted: The weighted load balancing algorithm is a method used to distribute incoming network traffic based on predefined weights assigned to each server. This allows some servers to handle more traffic than others, which is useful when servers have different capacities or performance characteristics.

  • Geography: The geography-based load balancing algorithm, also known as geo-load balancing or geo-location-based load balancing, distributes incoming traffic to servers based on the geographic location of the client. This approach aims to improve performance, reduce latency, and enhance user experience by routing requests to the nearest or most appropriate server based on the client's geographic location.

Database

  • Relational DB - A relational database is a type of database that stores and organizes data in tables (or relations) that are linked by defined relationships. Data in relational databases are structured in rows and columns, with each row representing a unique record and each column representing a field of the data. They use SQL (Structured Query Language) for defining and manipulating data. Some of the examples - MySQL, PostgreSQL and Oracle Database.

  • NoSQL DB - These are a category of database management systems that do not use the traditional table-based relational database structure. They are designed to handle a variety of data models, including document, key-value, graph, and wide-column stores. NoSQL databases are optimized for specific data models and scalability. Some of the examples - MongoDB, Redis, Cassandra.

  • In-Memory DB - An in-memory database is a database that primarily relies on main memory (RAM) for data storage, as opposed to disk storage. This allows for faster data retrieval and processing times compared to traditional disk-based databases. Examples are Redix and Apache Ignite.

  • Vertical Scaling(Scaling up) - It involves adding more resources (CPU, RAM, storage) to an existing database server to handle increased load. This is straightforward but has limitations since there's a maximum capacity for a single server. Example - Upgrading the RAM from 32GB to 64GB in a database server.

  • Horizontal Scaling(Scaling out) - Horizontal scaling involves adding more database servers to handle increased load. This typically requires distributing data and traffic across multiple servers. Example - Adding additional MySQL instances and distributing the data among them using sharding or replication.

  • Replication Scaling - Replication involves copying data from one database server (primary) to one or more others (replicas). This improves availability and fault tolerance. Replicas can be used for read operations to reduce the load on the primary server. Example - Setting up MySQL replication where the primary server handles writes and replica servers handle reads.

  • Sharding - Sharding is a method of horizontal scaling in which a database is partitioned into smaller, more manageable pieces called shards. Each shard contains a subset of the total data and is stored on a separate database server. This distributes the load and allows for scaling out.

  • Caching - It involves storing copies of frequently accessed data in a temporary storage layer (cache) to reduce access times and improve performance.

  • Indexing - It involves creating data structures that improve the speed of data retrieval operations on a database table. Indexes are typically created on columns that are frequently searched or used in JOIN operations.

  • Query optimization - It involves modifying database queries to improve their execution efficiency. This can include rewriting queries, using efficient join operations, and avoiding unnecessary calculations.

Reference - https://www.youtube.com/watch?v=F2FmTdLtb_4&t=2131s

That's it for this post
You can contact me on -

Instagram - https://www.instagram.com/supremacism__shubh/
LinkedIn - https://www.linkedin.com/in/shubham-tiwari-b7544b193/
Email - shubhmtiwri00@gmail.com

You can help me with some donation at the link below Thank you👇👇
https://www.buymeacoffee.com/waaduheck

Also check these posts as well




Top comments (1)

Collapse
 
blenderman profile image
BBM

Thanks for sharing this detailed overview of system design concepts! It was very informative. Quick question: Can you explain a bit more about how Weighted Load Balancing works in practice?