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

Sharding Fundamentals

Learning sharding as horizontal partitioning where each shard is an independent database.

Sharding Fundamentals

What you'll learn: You'll understand sharding as a horizontal partitioning strategy where each shard operates as an independent database.

What is Sharding?

Sharding is a specific implementation of horizontal partitioning where data is split across multiple physically separate databases, each called a shard. Unlike simple horizontal partitioning where partitions might exist within a single database system, each shard is completely independent—it has its own storage, processing power, and can even run on different servers or data centers.

Think of sharding like organizing a massive library system across multiple buildings. Instead of one giant library containing every book (which becomes slow and expensive), you distribute books across several independent libraries. Library A holds books starting with A-F, Library B holds G-M, and so on. Each library operates independently with its own staff and systems.

Key Characteristics

Independence: Each shard functions as a standalone database. If one shard goes down, others continue operating (though you lose access to that shard's data).

Data Distribution: Rows are distributed across shards based on a shard key—a field used to determine which shard holds each record. For example, you might shard users by geographic region or by user ID ranges.

Scalability: Need more capacity? Add more shards. This horizontal scaling is more cost-effective than vertically scaling a single massive server.

No Cross-Shard Operations (Ideally): Queries that need data from multiple shards become complex and slow, requiring coordination across independent systems.

Key Takeaway: Sharding distributes data across multiple independent databases (shards), enabling horizontal scaling but requiring careful design around the shard key to avoid expensive cross-shard operations.