Horizontal Scaling — NoSQL vs. Relational Databases

Tomoharu Tsutsumi
3 min readDec 26, 2024

One of the major advantages of NoSQL databases over relational databases (RDBs) is their ability to scale horizontally, which is also referred to as sharding. NoSQL databases, such as document stores, are designed to store “self-contained” objects, which means data can easily be distributed across multiple servers without worrying about complex joins or data relationships that are typically needed in relational databases.

Let’s consider a different example: a user profile with their posts, comments, and likes.

Example User Profile Document:

{
"user_id": 123,
"name": "John Doe",
"bio": "A passionate developer",
"posts": [
{ "post_id": 1, "content": "Just finished a project!", "timestamp": "2024-12-25" },
{ "post_id": 2, "content": "Excited about the new tech trends!", "timestamp": "2024-12-26" }
],
"comments": [
{ "comment_id": 1, "post_id": 1, "text": "Great work, John!" },
{ "comment_id": 2, "post_id": 2, "text": "Totally agree with you!" }
],
"likes": [
{ "user_id": 456, "post_id": 1 },
{ "user_id": 789, "post_id": 2 }
]
}

In NoSQL databases, this entire document can be stored as a single unit. All the user’s posts, comments, and likes are bundled together in one document. Since the document is self-contained, it can be distributed across servers without any need for cross-server joins.

Relational Database Challenge

In a relational database, we might store the same data in several different tables:

-- users table
user_id | name | bio
-------------------------
123 | John Doe | A passionate developer
-- posts table
post_id | user_id | content | timestamp
-------------------------------------------------------
1 | 123 | Just finished a project! | 2024-12-25
2 | 123 | Excited about new trends! | 2024-12-26
-- comments table
comment_id | post_id | user_id | text
-----------------------------------------
1 | 1 | 123 | Great work, John!
2 | 2 | 123 | Totally agree with you!
-- likes table
user_id | post_id
-------------------
456 | 1
789 | 2

In a relational database, to retrieve the user profile, we would need to join data from the users, posts, comments, and likes tables. This process becomes more complicated when scaling out. If the database is sharded, part of the comments might reside on one server, while likes are on another. The need to join these data points across different servers makes the operation slower and more complex.

Why NoSQL is Better for Horizontal Scaling

In contrast, NoSQL databases are built to handle such data distributions. Since the user profile document in NoSQL stores everything — posts, comments, and likes — within one self-contained document, it can easily be split across servers without complex joins. This makes the horizontal scaling process simpler and more efficient.

In summary, the real advantage of NoSQL databases lies in their ability to store self-contained objects that can be easily distributed across multiple servers, without the complications of joins that relational databases face when they scale horizontally.

Feel free to reach out to me on LinkedIn, which you can find below. Looking forward to connecting!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Tomoharu Tsutsumi
Tomoharu Tsutsumi

Written by Tomoharu Tsutsumi

5+ years Full Stack SWE (Ruby, Go, TypeScript, JavaScript) | Former Founding Engineer of AI Startup in Canada

No responses yet