What is a database shard
Simply put, it means that the data we store in the same database is scattered across multiple databases through a specific condition to achieve the effect of dispersing a single device load.
The segmentation of data (sharding) can be divided into two segmentation modes according to the type of its segmentation rules.
1. One is based on different tables to the different database (host), which can be called vertical segmentation of data
2. The other is based on the logical relationship of the data in the table, the data in the same table is split into multiple databases according to a certain condition, which is called the horizontal segmentation of the data.
How to implement Database Sharding
When a database is fragmented, the data is dispersed across multiple databases by a single database. At this time the system to query the need to switch between different databases for query, then how the system know the data to be queried in which database? What database do you want to insert when adding a record? These problems are very troublesome to deal with.
In this case, a database middleware mycat can be used to solve related problems.
What is Mycat?
Simply put, Mycat is: A new database middleware product, support MySQL cluster, provide high-availability data shard cluster. You can use Mycat as you would with MySQL. For developers, there is no sense of mycat.
Mycat Read/write separation
Database read/write separation is an essential function for large-scale systems or high-traffic Internet applications. For MySQL, the standard read-write separation is master-slave mode, a write node master followed by multiple read nodes, the number of read nodes depends on the system pressure, usually 1-3 read node configuration
Single Sign-on system
The main solution is the session sharing problem.
1. Use Redis to manage the session.
1) Key:token
2) Value: User Information
3) You may need to set the validity period.
4) The token must be stored in a cookie.
Shopping Cart
1. Not logged in: Use cookies to save shopping cart data
2. After login: Save the shopping cart data to Redis.
2, Shopping cart merger, should take the service side of the shopping cart prevail.
E-Commerce Activity Countdown Program:
1, determine a base time. You can use an SQL statement to fetch a current time from the database. SELECT now ();
2, the time of the start of the activity is fixed.
3. Use the activity start time-the base time can calculate the value of a second unit.
4. Set a key (activity start ID) in Redis. Set the expiration time of key to the time calculated in step three.
5. When the page is displayed, the effective time of key is removed. TTL command. Use JS countdown.
6. Once the activity starts, the key fails, indicating that the activity begins.
7, need in the activity logic, first determine whether the activity starts.
Second kill scenario:
8. Put the number of items into Redis.
9, seconds to kill when using the DECR command on the number of goods minus one. If it's not a negative note, grab it.
10. Once the return value becomes 0, the product is sold out.
Because the Cube mall is SOA-based architecture, the presentation and service tiers are different projects. Therefore, to implement a commodity list query requires communication between the two systems.
How do I implement remote communication?
1, Webservice: The efficiency is not high based on the SOAP protocol. Not recommended for use in projects.
2, the use of restful forms of service: Http+json. Applications in many projects. If there are too many services, the call between services is confusing and requires treatment services.
3, use Dubbo. Use the RPC protocol for remote invocation and use socket communication directly. The transfer efficiency is high, and the call relationship between the system and the number of calls can be counted.
What is Dubbo
Dubbo is a distributed service framework dedicated to providing high-performance and transparent RPC remote service invocation Scenarios
Dubbo is the management tool of the resource scheduling and governance center.
Java e-Commerce project Surface question (iii)