Skip to main content

Data Partitioning


In large-scale solutions, the amount of data to be processed can be huge. For effective data management, it is divided into separate partitions that can be managed and accessed independently. Choosing the right partitioning strategy is essential to maximize benefits, including improved scalability, performance, availability, and security. We will discuss three common partitioning strategies and considerations when designing partitions for scalability, performance, and availability.

Horizontal Partitioning In horizontal partitioning, also known as sharding, each partition is a data store with its schema, and each is referred to as a shard. Shards hold a specific subset of data such as all orders for a specific set of customers in an e-commerce application. One of the critical factors in implementing this partitioning strategy is the choice of sharding key. It is necessary to ensure even distribution of the workload across the shards, and the shard size should not exceed the scale limits of the data store. Furthermore, the sharding scheme should avoid creating hotspots that may impact performance and availability. Using a hash of a customer identifier instead of the first letter of a customer's name is a technique that helps to distribute the data more evenly across partitions.

Vertical Partitioning In vertical partitioning, each partition holds a subset of fields for items in the data store. The fields are divided according to their pattern of use, with frequently accessed fields in one partition and less frequently accessed fields in another. For example, an application might query product name, description, and price together when displaying product details to customers. The stock level and date when the product was last ordered from the manufacturer could be held in a separate partition because these two items are commonly used together.

Functional Partitioning In functional partitioning, data is aggregated according to how it is used by each bounded context in the system. It is a technique for improving isolation and data access performance for systems that can identify a bounded context for each distinct business area or service in the application. For example, an e-commerce system that implements separate business functions for invoicing and managing product inventory might store invoice data in one partition and product inventory data in another.

Designing Partitions for Scalability The partitioning strategy should be based on the data access patterns, such as the size of each query, the frequency of access, the inherent latency, and the compute processing requirements, such as stored procedures. Determining current and future scalability targets for data size and workload is crucial in distributing data across the partitions. Choosing an appropriate shard key in horizontal partitioning is critical to ensure even distribution of the workload across shards. It is important to make sure the resources available to each partition can handle scalability requirements in terms of data size and throughput. System monitoring verifies that the data is distributed as expected, and the partitions can handle the imposed load.

Designing Partitions for Query Performance Analyzing queries that perform slowly and critical queries that must always perform quickly is necessary when designing partitions for query performance. Partition the data that is causing slow performance, limit the size of each partition, and design the shard key to allow the application to find the partition quickly. Consider the location of a partition on the performance of queries and try to keep data in partitions that are geographically close to the applications and users that access it. If an entity has throughput and query performance requirements, use functional partitioning based on that entity. Parallel queries across partitions can improve query performance.

Designing Partitions for Availability Designing partitions to support independent management and maintenance is essential for improved availability. If a partition fails, it can be recovered independently without affecting instances of applications that access data in other partitions. Partitioning data by geographical area may allow scheduled maintenance to be performed on some partitions while others remain available.