0
0
HLDsystem_design~3 mins

Read-heavy vs write-heavy systems in HLD - When to Use Which

Choose your learning style9 modes available
The Big Idea

What if your app crashes just because it can't handle too many reads or writes? Let's fix that!

The Scenario

Imagine running a small library where you keep track of books by writing down every new book arrival and every time someone borrows a book on paper.

When many people want to look up books or borrow them, you have to flip through pages manually, and when new books arrive, you must add entries by hand.

The Problem

This manual method is slow because you spend too much time searching through pages for information.

It is error-prone since you might write wrong details or lose track of updates.

When many people want to check or add information at the same time, it becomes chaotic and confusing.

The Solution

By understanding if your system is read-heavy (more lookups) or write-heavy (more updates), you can design it to handle these tasks efficiently.

For read-heavy systems, you can optimize for fast data retrieval using caching and replicas.

For write-heavy systems, you focus on fast and reliable data updates with strong consistency and efficient storage.

Before vs After
Before
store = []
# Add book
store.append({'title': 'Book1'})
# Search book
for book in store:
    if book['title'] == 'Book1':
        print('Found')
After
cache = Cache()
# Add book
database.insert({'title': 'Book1'})
cache.invalidate('Book1')
# Search book
result = cache.get('Book1') or database.query('Book1')
if result:
    print('Found')
What It Enables

This understanding enables building systems that stay fast and reliable even under heavy use, making users happy and data safe.

Real Life Example

Social media platforms like Twitter are read-heavy because millions view posts, so they use caching and replicas.

Banking systems are write-heavy because many transactions update balances, so they focus on strong consistency and fast writes.

Key Takeaways

Manual data handling slows down with many reads or writes.

Read-heavy systems optimize fast data retrieval.

Write-heavy systems focus on fast, reliable updates.