Alex Xu Profile picture
Feb 23 โ€ข 9 tweets โ€ข 2 min read
In many large-scale applications, data is divided into partitions that can be accessed separately. There are two typical strategies for partitioning data. Image
๐Ÿ”น Vertical partitioning: it means some columns are moved to new tables. Each table contains the same number of rows but fewer columns (see diagram below). Image
Horizontal partitioning (often called sharding): divides a table into multiple smaller tables. Each table is a separate data store, and it contains the same number of columns, but fewer rows.

Horizontal partitioning is widely used so letโ€™s take a closer look Image
๐‘๐จ๐ฎ๐ญ๐ข๐ง๐  ๐š๐ฅ๐ ๐จ๐ซ๐ข๐ญ๐ก๐ฆ
The routing algorithm decides which partition (shard) stores the data.
๐Ÿ”น Range-based sharding. This algorithm uses ordered columns, such as integers, longs, timestamps, to separate the rows. For example, the diagram below uses the User ID column for range partition: User IDs 1 and 2 are in shard 1, User IDs 3 and 4 are in shard 2.
๐Ÿ”น Hash-based sharding. This algorithm applies a hash function to one column or several columns to decide which row goes to which table. For example, the diagram below uses ๐”๐ฌ๐ž๐ซ ๐ˆ๐ƒ ๐ฆ๐จ๐ 2 as a hash function. User IDs 1 and 3 are in shard 1, User IDs 2 and 4 are in shard 2
๐๐ž๐ง๐ž๐Ÿ๐ข๐ญ๐ฌ
๐Ÿ”น Facilitate horizontal scaling. Sharding facilitates the possibility of adding more machines to spread out the load.

๐Ÿ”น Shorten response time. By sharding one table into multiple tables, queries go over fewer rows, and results are returned much more quickly.
๐ƒ๐ซ๐š๐ฐ๐›๐š๐œ๐ค๐ฌ
๐Ÿ”น The order by operation is more complicated. Usually, we need to fetch data from different shards and sort the data in the application's code.

๐Ÿ”น Uneven distribution. Some shards may contain more data than others (this is also called the hotspot).
This topic is very big and Iโ€™m sure I missed a lot of important details. What else do you think is important for data partitioning?

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Alex Xu

Alex Xu Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @alexxubyte

Feb 25
You probably heard about ๐’๐–๐ˆ๐…๐“. What is SWIFT? What role does it play in cross-border payments? Let's take a look.

The Society for Worldwide Interbank Financial Telecommunication (SWIFT) is the main secure ๐ฆ๐ž๐ฌ๐ฌ๐š๐ ๐ข๐ง๐  ๐ฌ๐ฒ๐ฌ๐ญ๐ž๐ฆ that links the worldโ€™s banks. 1/9 Image
The Belgium-based system is run by its member banks and handles millions of payment messages per day. The diagram below illustrates how payment messages are transmitted from Bank A (in New York) to Bank B (in London). 2/9 Image
Step 1: Bank A sends a message with transfer details to Regional Processor A in New York. The destination is Bank B. 3/9 Image
Read 9 tweets
Feb 24
In modern architecture, systems are broken up into small and independent building blocks with well-defined interfaces between them. Message queues provide communication and coordination for those building blocks. Today, letโ€™s discuss at-most once, at-least once, and exactly once. Image
๐€๐ญ-๐ฆ๐จ๐ฌ๐ญ ๐จ๐ง๐œ๐ž
As the name suggests, at-most once means a message will be delivered not more than once. Messages may be lost but are not redelivered. This is how at-most once delivery works at the high level. Image
Use cases: It is suitable for use cases like monitoring metrics, where a small amount of data loss is acceptable.

๐€๐ญ-๐ฅ๐ž๐š๐ฌ๐ญ ๐จ๐ง๐œ๐ž
With this data delivery semantic, itโ€™s acceptable to deliver a message more than once, but no message should be lost. Image
Read 8 tweets
Feb 18
A really cool technique thatโ€™s commonly used in object storage such as S3 to improve durability is called ๐„๐ซ๐š๐ฌ๐ฎ๐ซ๐ž ๐‚๐จ๐๐ข๐ง๐ . Letโ€™s take a look at how it works. 1/7 Image
Erasure coding deals with data durability differently from replication. It chunks data into smaller pieces and creates parities for redundancy. In the event of failures, we can use chunk data and parities to reconstruct the data. 4 + 2 erasure coding is shown in Figure 1. 2/7
1๏ธโƒฃ Data is broken up into four even-sized data chunks d1, d2, d3, and d4.

2๏ธโƒฃ The mathematical formula is used to calculate the parities p1 and p2. To give a much simplified example, p1 = d1 + 2*d2 - d3 + 4*d4 and p2 = -d1 + 5*d2 + d3 - 3*d4. 3/7 Image
Read 7 tweets
Feb 16
Today, letโ€™s design an S3 like object storage system.

Before we dive into the design, letโ€™s define some terms. 1/11 Image
๐๐ฎ๐œ๐ค๐ž๐ญ. A logical container for objects. The bucket name is globally unique. To upload data to S3, we must first create a bucket. 2/11 Image
๐Ž๐›๐ฃ๐ž๐œ๐ญ. An object is an individual piece of data we store in a bucket. It contains object data (also called payload) and metadata. Object data can be any sequence of bytes we want to store. The metadata is a set of name-value pairs that describe the object. 3/11 Image
Read 11 tweets
Jan 26
I'm the author of the best-selling book System Design Interview-An Insiderโ€™s Guide. 11 days ago, two fraudsters hijacked the "Buy Now" button on Amazon, fulfilling all orders with a different book. I'm helpless to do anything. A sad story on self-publishing: a thread.
How do I know Amazon fulfills pirated copies? I clicked on the โ€œBuy Nowโ€ button and bought them. One had similar content but with a different layout and was printed on inferior quality paper. My book has 309 pages: the pirated one only 276 pages and a completely different ISBN.
How bad is the issue? I estimate between 60%-80% of the copies sold in the past 11 days are pirated books fulfilled by Amazon. You can see the โ€œBuy Nowโ€ button hijacking in action here: amzn.to/3tX4r4b
Read 10 tweets
Jan 25
One picture is worth more than a thousand words. In this thread, we will take a look at what happens when Alice sends an email to Bob.1/5
1. Alice logs in to her Outlook client, composes an email, and presses โ€œsendโ€. The email is sent to the Outlook mail server. The communication protocol between the Outlook client and mail server is SMTP.2/5
2. Outlook mail server queries the DNS (not shown in the diagram) to find the address of the recipientโ€™s SMTP server. In this case, it is Gmailโ€™s SMTP server. Next, it transfers the email to the Gmail mail server. The communication protocol between the mail servers is SMTP.3/5
Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(