Course contentsShow
← Computer Science
Lesson 2683 of 2,87260. Distributed Data and CommunicationFree lesson

Horizontal vs Vertical Partitioning

Distinguishing between splitting data by rows (horizontal) versus columns (vertical).

Horizontal vs Vertical Partitioning

What You'll Learn

You'll understand the fundamental distinction between splitting data by rows (horizontal partitioning) versus splitting by columns (vertical partitioning).

The Core Idea

In distributed systems, partitioning divides large datasets across multiple nodes. There are two primary ways to slice your data:

Horizontal Partitioning splits data by rows. Each partition contains a subset of records, but every partition has the same schema with all columns. Think of it like distributing pages of a phone book across different servers—each server gets different people's entries, but each entry has name, address, and phone number.

For example, if you have a users table with 1 million rows, horizontal partitioning might put users 1–500,000 on Node A and users 500,001–1,000,000 on Node B. Each node stores complete user records.

Vertical Partitioning splits data by columns. Different partitions contain different attributes of the same entities. Imagine separating a phone book into two: one book contains only names and addresses, another contains only phone numbers and emails.

Using the same users table, vertical partitioning might store user_id and username on Node A, while email, address, and preferences live on Node B. To reconstruct a complete user record, you'd need to query both nodes.

When to Use Each

Horizontal partitioning (also called sharding) scales well when you need to distribute load across many records—ideal for high-traffic applications. Vertical partitioning is useful when different columns have different access patterns—frequently accessed "hot" columns can live separately from rarely used "cold" columns.

Key Takeaway: Horizontal partitioning divides data by rows (different records per partition), while vertical partitioning divides by columns (different attributes per partition); choose based on your access patterns and scaling needs.