Database Slice Mode

Source: Internet
Author: User

The database slicing mode focuses on achieving horizontal scaling. Slicing is accessing two or more database slices from a single database to the split data. Each slice has the same schema as the original database. Most of the data is distributed in each slice of each row. The data that is merged from the slices is the same as the original database. Slices are also approximately equivalent to horizontal partitioning (horizontal partitioning), and there are many places on the web that use horizontal partitioning to refer to slices, and there is actually a difference between them. Indeed, the idea of slicing is from the idea of partitioning, but the database partition is basically processing at the level of the data object, such as the partitioning of tables and indexes, the ability to have different physical storage properties on each sub-dataset, or a single database-scoped operation, while slices are capable of cross-database or even cross-physical machines.

Contextual (context)

Database slicing is an effective response to the following challenges:

      1. application database queries exceed the query capability of a single database node.
      2. Application database updates exceed the single database transaction capacity, resulting in unacceptable time or timeouts.
      3. The application database network bandwidth exceeds the bandwidth page of a single database node, resulting in unacceptable times or timeouts.
      4. Application database storage requirements have exceeded the capacity of a single database node.

Mechanism

Traditional (non-shared) databases are deployed on a single server node. Any database running on a single node is limited by the current node capacity. Contention for resources such as CPU, memory, disk speed, data size, and network bandwidth can damage the database's ability to measure database activity in relation to the volume. Excessive contention may also make the database unsustainable. When a single node is no longer sufficient, there are a number of potential approaches in order to achieve an application database scaling. Some examples include: distributed queries loaded into slave nodes, split by data type to multiple databases and vertically scaled database servers. handles query loading (not write/update) from nodes that are copied from master data, and from nodes that are read-only consistent with typical transactions. Another option is to split into multiple databases by data type, such as inventory data in one database and employee data in another database. Each node contains a subset of data called slices. Overall, the data in all slices renders a complete logical database. When the database service inherits slices, the slice collection appears in a single database connection string. This abstraction is good for simplifying the application programming model.

As shown, the data rows are distributed to the slices, maintaining the same structure, the above one slicing the storage id=1,2, and the other storing the id=3,4,5 records.

Segmentation and Strategy

As with many other technologies, a partial compromise is needed to make a shard. Because slices are not a local database technology-that is, they must be implemented in your application-you need to work out your sharding strategy before you start slicing. Primary keys and cross-cut queries play an important role in slicing, primarily by defining what you can't do.

Primary key

Slices take advantage of multiple databases, where all the databases work independently and do not interfere with other slices. Therefore, if you rely on database sequences (such as automatic primary key generation), it is likely that the same primary key will appear in a single database set. You can reconcile a sequence across a distributed database, but this increases the complexity of the system. The safest way to avoid the same primary key is to have the application (the application will manage the sharding system) generate a primary key.

Cross-Slice query

Most sharding implementations do not support cross-slice queries, which means that if you want to take advantage of two datasets of different shards, you must handle the extra length. (Interestingly, Amazon's SimpleDB also prohibits cross-domain queries) For example, if you store US customer information in slice 1, you'll also need to store all the relevant data here. If you try to store those data in slice 2, the situation becomes complex and system performance may be affected. This situation is also relevant to the point mentioned earlier-if you need to cross-slice a connection for some reason, it's best to manage the key in a way that eliminates duplication!

It is clear that the sharding strategy must be fully considered before the database is established. Once you've chosen a particular direction, you're almost bound to it-it's hard to easily move data after slicing.

A policy example

because sharding binds you to a Linetype data model (that is, you cannot easily connect data in different slices), you must have a clear idea of how to logically organize the data in each shard. This can be achieved by focusing on the primary node in the domain. As in an e-commerce system, the primary node can be an order or a customer. Therefore, if you select customer as the node for the segmentation strategy, all data related to the customer is moved to the respective Shard, but you still have to choose which shard to move the data to. for customers, you can slice by location (Europe, Asia, Africa, and so on), or you can slice it based on other elements. It is up to you to decide. However, your segmentation strategy should include a way to distribute data evenly across all shards. The overall concept of sharding is to split large datasets into small datasets, so if a particular e-commerce domain contains a large set of European customers and a relatively small set of US customers, then segmentation based on the location of the customer might not make sense.


Attention

For example, historical table information such as transaction history, if a record contains both seller information and buyer information, if over time, the buyer and the seller will continue to trade with other users, so that the inevitable two trader's information will be distributed to different database slices, and then if the buyer for the trader to inquire, Will span more slices, and the overhead will be larger.

Slicing is not a silver bullet for database expansion scenarios, and it is not suitable for scenarios such as transaction-oriented applications that can be very complex. For transactions that span different db, it is difficult to guarantee integrity and outweigh the gains.

Be sure to determine the size and growth of your application before you slice it. The cost (or disadvantage) of sharding includes the cost of encoding specific application logic for how data is stored and retrieved. After slicing, you are more or less locked into your segmentation model because it is not easy to re-slice.

If implemented correctly, sharding can be used to solve traditional RDBMS scale and speed issues. Sharding is a very cost-effective decision for organizations that are bound to a relational infrastructure and cannot continue to upgrade their hardware to meet a large number of scalable data storage requirements.

Database Slice Mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.