On this page
Data Partitioning a technique to break up a big database (DB) into many smaller parts It is the process of splitting up a DB/table across multiple machinesto improve the manageability, performance, availability, and load balancing of an application after a certain scale pointit is cheaper and more feasible to scale horizontally It is more expensive to grow it vertically by adding beefier servers Partitioning Methods 3 most popular schemes used by various large scale applicationsHorizontal partitioningput different rows into different tables also called as range based partitioningas we are storing different ranges of data in separate tables also called as Data Sharding key problemif the value whose range is used for partitioning isn’t chosen carefullythe partitioning scheme will lead to unbalanced servers Vertical Partitioningdivide our data to store tables related to a specific feature in their own server it is straightforward to implement and has a low impact on the application main problemif our application experiences additional growthit may be necessary to further partition a feature specific DB across various servers Directory Based PartitioningA loosely coupled approach to work around issues mentioned in the above schemesis to create a lookup servicewhich knows your current partitioning scheme and abstracts it away from the DB access code to find out where a particular data entity resideswe query the directory server that holds the mapping between each tuple key to its DB server loosely coupled approach meanscan perform tasks likeadding servers to the DB pool changing our partitioning scheme without having an impact on the application Partitioning Criteria Key or Hash-based partitioningapply a hash function to some key attributes of the entity we are storing; that yields the partition number This approach should ensure a uniform allocation of data among servers fundamental problemit effectively fixes the total number of DB serversadding new servers = changing the hash functionthis would require redistribution of data and downtime for the serviceA workaround for this problem is to use Consistent Hashing List partitioningeach partition is assigned a list of valueswhenever we want to insert a new record, we will see which partition contains our key and then store it there Round-robin partitioning
a simple strategy that ensures uniform data distribution
With ‘n’ partitions, the ‘i’ tuple is assigned to partition (i mod n)
d. Composite partitioning
combine any of the above partitioning schemes to devise a new scheme
e.g.: first applying a list partitioning scheme and then a hash based partitioning
Consistent hashing could be considered a composite of hash and list partitioning
where the hash reduces the key space to a size that can be listed Common Problems of Data Partitioning On a partitioned database, there are certain extra constraints on the different operations that can be performedconstraints are due to operations across multiple tables rows in the same table will no longer run on the same server Constraints and additional complexities introduced by partitioningJoins and DenormalizationPerforming joins on a database which is running on one server is straightforwardbut will no longer be so once once a database is partitioned and spread across multiple machinesbecause joins that span database partitions will not be feasible Such joins will not be performance efficient since data has to be compiled from multiple servers solution: denormalize the databaseso that queries that previously required joins can be performed from a single table however, service now has to deal with all the perils of denormalization such as data inconsistency Referential integritytrying to enforce data integrity constraints such as foreign keys in a partitioned database can be difficult Most of RDBMS do not support foreign keys constraints across databases on different database serversthis means that apps that require referential integrity on partitioned databases have to enforce it in app codein such cases, applications have to run regular SQL jobs to clean up dangling references Rebalancingmany reasons we have to change our partitioning schemeThe data distribution is not uniform There is a lot of load on a partition In such cases, either we have to create more DB partitions or have to rebalance existing partitionsthis means the partitioning scheme changed and all existing data moved to new locations Doing this without incurring downtime is extremely difficult Using a scheme like directory based partitioning make rebalancing a palatable experienceat the cost of increasing the complexity of the system and creating a new single point of failure (i.e. the lookup service/database)