{
    "componentChunkName": "component---src-templates-case-study-detail-ts",
    "path": "/case-studies/17",
    "result": {"pageContext":{"next":{"id":18,"attributes":{"feature":false,"title":"Apache ShardingSphere & Bilibili","content":"> To further understand application scenarios, and enterprises’ needs, and improve dev teams’ understanding of Apache ShardingSphere, our community launched the “Enterprise Visits”\n> series.\n\n\n[Apache ShardingSphere](https://shardingsphere.apache.org/)’s core contributor team was invited to the headquarters of [Bilibili](https://www.bilibili.com/) in Shanghai. Our PMC Chair, Zhang Liang, discussed with Bilibili’s tech team the e-commerce and digital entertainment verticals application scenarios, and the capabilities of different versions of ShardingSphere.\n\nWith the unprecedented growth of data volume and increasingly diversified data application scenarios, different platforms, businesses, and scenarios have resulted in database applications’ fragmentation. The challenges facing databases today are totally different from the ones they were conceived to solve. This is also reflected in the growth of Bilibili’s e-commerce business.\n\nFor over a decade, Bilibili has built an ecosystem community centered on users, creators, and content, while producing high-quality videos as well. With an increasing number of users, Bilibili has also gradually developed peripheral business ecosystems such as its subscription revenue model. The expansion of business lines and application scenarios brought great challenges for Bilibili’s tech team, especially in the management and application of backend data.\n\nDuring the visit, our community and Bilibili mainly discussed these three points:\n\n## The SQL warm-up feature jointly built with Bilibili:\nWhen Bilibili queries goods and orders with batch priority in its business, it is often necessary to manually warm-up SQL during the initial linking process to improve overall performance. However, in the process of manual warm-up, parameters of different lengths cannot be used as a SQL to warm-up due to the use of `foreach` syntax of the [Mybatis](https://mybatis.org/mybatis-3/index.html) framework.\n\nApache ShardingSphere can see the SQL execution plan through the `preview`, thus warming up the SQL. In the future, we plan to provide a separate SQL warm-up interface and merge the SQL warm-up time into the startup time. ShardingSphere will start on its own after SQL is warmed up.\n\n[Apache ShardingSphere](https://shardingsphere.apache.org/) is an open-source project driven by the needs of the community. Currently, many capabilities’ development is driven by specific user requirements, which are fed back to the community after development and gradually integrated into Apache ShardingSphere.\n\nTherefore, the ShardingSphere community invited Bilibili’s tech team to get involved in terms of the SQL warm-up feature.\n\nWith the expansion of Apache ShardingSphere’s application scenarios, there is a higher expectation for ShardingSphere’s capabilities to adapt to a variety of special business scenarios. In the previous “Enterprise Visits” series, the ShardingSphere community recognized that even though it has more than 100 feature modules, enterprises from various verticals have different expectations from ShardingSphere.\n\n## Bilibili’s circuit breaker automation in traffic spike scenarios:\n\nWith the growth of Bilibili’s e-commerce scale, as is often the case with many e-commerce businesses, started to adopt front-end strategies such as cash rebates and flash deals in order to improve user retention.\n\nOn the backend, however, when the rebate performance of the warehouse is equal to the number of concurrent transactions while exceeding its own connection number limit, it can only be stopped through manual disconnection via DBA based on the number of SKU at the business level. Manual intervention is inefficient and consumes DBAs’ energy, so [ShardingSphere-Proxy](https://shardingsphere.apache.org/document/current/en/quick-start/shardingsphere-proxy-quick-start/) is expected to provide an automatic circuit breaker capability.\n\nHowever, the flash deal scenario is too demanding, so [Redis](https://redis.io/) still represents a better choice. Achieving automation simply requires setting rules and thresholds.\n\nSinking data to Proxy can also achieve the capabilities of Redis, but no matter how the upper layer changes, the bottom of the database will not change. Therefore, it is better for DBAs to take the initiative to operate the circuit breaker mechanism. Otherwise, after setting a threshold, if the connection between the application and the database has a slight timeout, a large number of transactions will be cut off instantly, which can easily cause a business outage.\n\nCurrently, a better way is to dig out all kinds of key information and display it on the visual interface based on Proxy, to facilitate the real-time comparison and operation of DBA instead of achieving automation.\n\n## The Apache ShardingSphere registry:\nIn the Apache ShardingSphere architecture, the registry provides distributed governance capabilities and is fully open to users since its computing node ([Shardingsphere-proxy](https://shardingsphere.apache.org/document/current/en/quick-start/shardingsphere-proxy-quick-start/)) is stateless without data storage capability. Therefore, user accounts and authorization information need to be stored in the registry.\n\nConcurrently, with the help of the registry, Apache ShardingSphere can distribute information to multiple computing nodes in the cluster in real-time, greatly reducing maintenance costs for users when using the cluster and improving management efficiency.\n\nIn cluster mode, Apache ShardingSphere integrates third-party registry components [ZooKeeper](https://zookeeper.apache.org/) and [Etcd](https://etcd.io/) to achieve metadata and configuration sharing in the cluster environment. At the same time, with the help of the notification and coordination ability of the registry, it ensures the real-time synchronization of the cluster when the shared data changes. And the business will not be aware of changes from the registry.\n\n## Q&A with Bilibili\n**Q: Is there a performance loss when using JDBC to connect to the governance center?**\n\nA: No. It only connects to the governance center during initialization, and the governance center will send a push when there is a change.\n\n**Q: How does [Sysbench](https://wiki.gentoo.org/wiki/Sysbench) conduct a stress test on Apache ShardingSphere?**\n\nA: The two deployment types of Apache ShardingSphere, JDBC and Proxy, are both tested by Sysbench. ShardingSphere has a newly designed Sysbench-like Java program on the JDBC end that can be used to conduct a pressure test to JDBC and Proxy. It can also ensure that the official Sysbench and our Java program share the same standard.\n\n**Q: Can ShardingSphere converge the connection number?**\n\nA: ShardingSphere-Proxy can converge the connection number, but it will definitely lead to performance loss.\n\n**Q: Can Proxy identify slow SQL?**\n\nA: Currently, the open-source version doesn’t support this function, because most users of the open-source version are Internet enterprises with a low tolerance for performance loss. Thus, the number of probes is relatively small.\n\n**Q: Does [ElasticJob](https://shardingsphere.apache.org/elasticjob/) belong to Apache ShardingSphere?**\n\nA: ElasticJob is currently used as the migration tool by Apache ShardingSphere. Additionally, ElasticJob can also be used for liveness probes.\n\n**Q: Are Internet enterprises using Proxy on a large scale?**\n\nA: Most Internet users choose the mixed deployment model, using JDBC for development and better performance, and Proxy for management. Financial customers prefer to use Proxy because they can take Proxy as a database for unified management without additional learning costs.\n\n**Q: We are currently using ShardingSphere version 4.1.1, what does it support for transactions?**\n\nA: Both versions 4.11 and 5.1.0 support [XA](https://docs.oracle.com/database/121/TTCDV/xa_dtp.htm#TTCDV327) distributed transaction management. We plan to develop the global transaction manager ([GTM](https://docs.oracle.com/cd/E17276_01/html/programmer_reference/xa_build.html)) which is scheduled to start in the second half of this year.\n\n## Get in touch with us\nIf you have applied Apache ShardingSphere solutions in your business or if you want to quickly understand and introduce the Apache ShardingSphere 5.X ecosystem to your business, you’ll probably like for someone from our community to help you out and share the Apache ShardingSphere technology with your team.\n\nFeel free to reach out to us on one of our official community channels, such as Twitter or Slack.\n\nIf we both agree that ShardingSphere is suitable for your business scenarios, our community team will be happy to connect with you and your engineers to take their questions.\n\n**Apache ShardingSphere Project Links:**\n\n[ShardingSphere Github](https://github.com/apache/shardingsphere/issues?page=1&q=is%3Aopen+is%3Aissue+label%3A%22project%3A+OpenForce+2022%22)\n\n[ShardingSphere Twitter](https://twitter.com/ShardingSphere)\n\n[ShardingSphere Slack](https://join.slack.com/t/apacheshardingsphere/shared_invite/zt-sbdde7ie-SjDqo9~I4rYcR18bq0SYTg)\n\n[Contributor Guide](https://shardingsphere.apache.org/community/cn/contribute/)","date":"2022-06-07","author":"SphereEx","excerpt":"The ShardingSphere community visited one of its enterprise users: the major Chinese video-on-demand streaming platform - Bilibili. Originally known for anime, comics & games, Bilibili has since expanded - as did its total users.\n","metaDescription":"Bilibili is an online entertainment platform featuring videos, live broadcasting, and mobile games.","createdAt":"2022-09-26T06:51:57.325Z","updatedAt":"2022-09-27T06:59:09.655Z","publishedAt":"2022-09-27T06:59:09.651Z","locale":"en","caseStudiesType":{"data":{"id":9,"attributes":{"name":"Internet","createdAt":"2022-09-26T10:34:03.086Z","updatedAt":"2022-09-27T06:59:34.838Z","publishedAt":"2022-09-27T06:59:34.836Z","locale":"en"}}},"cover":{"data":{"id":337,"attributes":{"name":"bilibili.jpeg","alternativeText":"bilibili.jpeg","caption":"bilibili.jpeg","width":1024,"height":450,"formats":{"thumbnail":{"name":"thumbnail_bilibili.jpeg","hash":"thumbnail_bilibili_2865813b49","ext":".jpeg","mime":"image/jpeg","width":245,"height":108,"size":10.11,"path":null,"url":"https://official-media.sphere-ex.com/thumbnail_bilibili_2865813b49.jpeg"},"large":{"name":"large_bilibili.jpeg","hash":"large_bilibili_2865813b49","ext":".jpeg","mime":"image/jpeg","width":1000,"height":439,"size":86.56,"path":null,"url":"https://official-media.sphere-ex.com/large_bilibili_2865813b49.jpeg"},"medium":{"name":"medium_bilibili.jpeg","hash":"medium_bilibili_2865813b49","ext":".jpeg","mime":"image/jpeg","width":750,"height":330,"size":56.83,"path":null,"url":"https://official-media.sphere-ex.com/medium_bilibili_2865813b49.jpeg"},"small":{"name":"small_bilibili.jpeg","hash":"small_bilibili_2865813b49","ext":".jpeg","mime":"image/jpeg","width":500,"height":220,"size":30.65,"path":null,"url":"https://official-media.sphere-ex.com/small_bilibili_2865813b49.jpeg"}},"hash":"bilibili_2865813b49","ext":".jpeg","mime":"image/jpeg","size":90.83,"url":"https://official-media.sphere-ex.com/bilibili_2865813b49.jpeg","previewUrl":null,"provider":"strapi-provider-upload-s3-compat","provider_metadata":null,"createdAt":"2022-09-26T06:52:45.832Z","updatedAt":"2022-09-26T06:52:45.832Z"}}},"metaLogo":{"data":{"id":352,"attributes":{"name":"bilibili logo.jpg","alternativeText":"bilibili logo.jpg","caption":"bilibili logo.jpg","width":1050,"height":758,"formats":{"thumbnail":{"name":"thumbnail_bilibili logo.jpg","hash":"thumbnail_bilibili_logo_560e3483f4","ext":".jpg","mime":"image/jpeg","width":216,"height":156,"size":4.21,"path":null,"url":"https://official-media.sphere-ex.com/thumbnail_bilibili_logo_560e3483f4.jpg"},"large":{"name":"large_bilibili logo.jpg","hash":"large_bilibili_logo_560e3483f4","ext":".jpg","mime":"image/jpeg","width":1000,"height":722,"size":27.06,"path":null,"url":"https://official-media.sphere-ex.com/large_bilibili_logo_560e3483f4.jpg"},"medium":{"name":"medium_bilibili logo.jpg","hash":"medium_bilibili_logo_560e3483f4","ext":".jpg","mime":"image/jpeg","width":750,"height":541,"size":18.89,"path":null,"url":"https://official-media.sphere-ex.com/medium_bilibili_logo_560e3483f4.jpg"},"small":{"name":"small_bilibili logo.jpg","hash":"small_bilibili_logo_560e3483f4","ext":".jpg","mime":"image/jpeg","width":500,"height":361,"size":11.77,"path":null,"url":"https://official-media.sphere-ex.com/small_bilibili_logo_560e3483f4.jpg"}},"hash":"bilibili_logo_560e3483f4","ext":".jpg","mime":"image/jpeg","size":27.87,"url":"https://official-media.sphere-ex.com/bilibili_logo_560e3483f4.jpg","previewUrl":null,"provider":"strapi-provider-upload-s3-compat","provider_metadata":null,"createdAt":"2022-09-26T08:40:54.591Z","updatedAt":"2022-09-26T08:40:54.591Z"}}},"localizations":{"data":[]}}},"prev":{"id":16,"attributes":{"feature":false,"title":"Apache ShardingSphere & China Unicom Digital Technology: Ensuring Stability, Efficiency, and Replicability at Scale","content":"China Unicom Digital Tech is the subsidiary of [China Unicom](https://www.chinaunicom.com.hk/en/global/home.php), a global leading telecommunication operator with over 310 million subscribers as of 2021.\n\nThe company integrates with China Unicom’s capabilities such as cloud computing, Big Data, IoT, AI, blockchain, and security and touches on smart city, industrial internet, ecological protection, cultural tourism, and other fields.\n\nUnicom Digital Tech has accumulated a large number of industry benchmark cases and successfully provided customers with diverse and professional products & services.\n\n## Background\nIn recent years, dozens of service hotline platforms have been launched with the help of Unicom Digital Tech, in a bid to improve enterprise and government services.\n\nThe service hotlines are characterized by high concurrency and large amounts of data. Every time we dial a hotline, a work order record is generated. The business volumes of a hotline during the epidemic have increased several times compared to the past.\n\nIn the work order module of the government or emergency services hotlines, to meet the business needs of massive amounts of data and high stability, Unicom Digital Tech adopts [ShardingSphere](https://shardingsphere.apache.org/) to carry out sharding and store work order information.\n\n## Business challenges\nGovernment service hotlines are the main channel through which the government interacts with enterprises and the public. It provides 24/7 services for the public through a single telephone number.\n\nIn addition to dealing with work orders, it also involves services such as telephone traffic, Wiki, voice chat, etc.\n\nIn the system planning stage, the database layer is the cornerstone of the business system, so the technology selection process is crucial. System stability is a hard indicator, followed by performance, which directly affects the hotline’s service capability.\n\nAt the same time, it should allow for easy maintenance and management, and facilitate system upgrades and backend maintenance.\n\nThe hotline service raises the following requirements for database architecture selection:\n\n- Maturity and stability\n- High performance\n- Easy maintenance\n- Low coupling of business code\n\n## Why did Unicom Digital Technology choose ShardingSphere?\nThe technical team conducted several rounds of research and tests in terms of stability, features, access mode, and product performance, and they finally choose the “ShardingSphere + [MySQL](https://www.mysql.com/)” distributed database solution.\n\n- **Advanced concept**\n\nAn increasing number of application scenarios have exacerbated database fragmentation. [Database Plus](https://faun.pub/whats-the-database-plus-concepand-what-challenges-can-it-solve-715920ba65aa) is designed to build an ecosystem on top of fragmented heterogeneous databases and provide enhancements capability for the database.\n\nAdditionally, it can prevent database binding, achieve independent control, add more features to the original database, and improve the overall feature ceiling of the data infrastructure.\n\n- **Maturity and stability**\n\nThe ShardingSphere project started in 2016. Following years of R&D and iterations, the project has been polished and has proven its stability, maturity, and reliability in multiple Internet scenarios.\n\n- **Comprehensive features**\n\nIn addition to sharding capability, ShardingSphere is also capable of data encryption & decryption and shadow DB, which were also among the evaluation indicators of the technical team.\n\nThe scenario requirements of security and stress testing can be met by a set of technology stacks. ShardingSphere’s capabilities provide improved support for the construction and architecture expansion of the hotline system.\n\n- **High compatibility / easy access**\n\nShardingSphere is compatible with the MySQL protocol and supports multiple syntaxes. In the development process, there is almost no need to worry about access to SQL as it is really convenient.\n\n- **High performance**\n\nWhen the hotline is busy, thousands of on-duty operators are online. The work order record includes tens of millions of records, which create a certain demand for performance.\n\nShardingSphere-JDBC is positioned as a lightweight Java framework with ideal stress test results and data, which can meet the requirements of government system service capabilities.\n\n- **Simplified operation & maintenance**\n\nOn the basis of JDBC’s high performance, ShardingSphere also provides a Proxy friendly to ops teams, which can be directly accessed using common clients.\n\nIn addition to the trade-offs of the above five key considerations, other database middleware products were also taken into consideration. The following table indicates the comparison between ShardingSphere and [MyCat](http://mycat.sourceforge.net/).\n![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mc2d1n3csc1bf9vu26ab.png)\n \n\n## Solutions\nAs “ShardingSphere+MySQL” ensures stability, ease of use, and ultimate performance, this configuration has been replicated and used in many government and enterprise service hotline projects of Unicom Digital Tech.\n\n- **Deployment mode**\nThe combination of [ShardingSphere-JDBC](https://shardingsphere.apache.org/document/current/en/overview/#shardingsphere-jdbc) and [ShardingSphere-Proxy](https://shardingsphere.apache.org/document/current/en/quick-start/shardingsphere-proxy-quick-start/) ensures both system performance and maintainability.\n\n- **Sharding key / sharding algorithm**\nThe work order table of the hotline service is relatively large, and the logic is simple to use. Therefore, the work order ID is selected as the sharding key, and the data is distributed through the hash algorithm.\n\n- **Migration**\nThe new project does not involve historical data, so there is no need to consider the data migration process, and it can be directly used when it goes live.\n\n- **Implementation process**\nOwing to the comprehensive evaluation of the technical scheme and multiple copies of the scheme, the implementation process is smooth.\n\n- **System architecture**\nThe hotline service module adopts the micro-service architecture\n\nThe business module of the hotline service adopts the micro-service architecture, with nodes ranging from ten to dozens, depending on the scale of specific provinces and cities. At the database layer, physical machines are used to deploy three-node MHA. Each hotline system requires four sets of MHA in general.\n![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v8k9lv1l3pjxme0e7sxs.png)\n \n\n## Advantages\n\n> Business\n\n-  the client mode. It ensures the government hotline’s requirements on performance to the greatest degree.\n- System stability provides strong support for business continuity.\n\n> R&D\n\n- Excellent compatibility. It is compatible with mainstream database SQL syntax and can be used after docking.\n- Comprehensive features. It supports read/write splitting, data encryption, and full-link stress testing, with strong system scalability.\n\n> OPS\n\n- It supports the proxy mode and provides easy maintenance for Ops teams.\n\n> Technology selection\n\n- It prevents database binding and provides enough flexibility for future upgrades.\n\n## Conclusion\nThe hotline service cases of China Unicom Digital Tech verified ShardingSphere’s capability to support government service scenarios and further proved that ShardingSphere can be used in any industry.\n\n## Project Links:\n[ShardingSphere Github](https://github.com/apache/shardingsphere/issues?page=1&q=is%3Aopen+is%3Aissue+label%3A%22project%3A+OpenForce+2022%22)\n\n[ShardingSphere Twitter](https://github.com/apache/shardingsphere/issues?page=1&q=is%3Aopen+is%3Aissue+label%3A%22project%3A+OpenForce+2022%22)\n\n[ShardingSphere Slack](https://join.slack.com/t/apacheshardingsphere/shared_invite/zt-sbdde7ie-SjDqo9~I4rYcR18bq0SYTg)\n\n[Contributor Guide](https://shardingsphere.apache.org/community/cn/contribute/)","date":"2022-07-20","author":"SphereEx","excerpt":"China Unicom Digital Technology, a global telco operator with 310 million subscribers, chose ShardingSphere to manage its gov and enterprise hotlines data infrastructure.","metaDescription":"China Unicom is a company that provides broadband communications and information services. It has subsidiaries in 31 provinces (autonomous regions and municipalities) across China and many countries and regions around the world.","createdAt":"2022-09-26T06:38:43.311Z","updatedAt":"2022-09-27T06:55:16.269Z","publishedAt":"2022-09-27T06:55:16.266Z","locale":"en","caseStudiesType":{"data":{"id":7,"attributes":{"name":"Telecom","createdAt":"2022-09-26T10:29:57.244Z","updatedAt":"2022-09-27T06:59:48.158Z","publishedAt":"2022-09-27T06:59:48.156Z","locale":"en"}}},"cover":{"data":{"id":335,"attributes":{"name":"China unicom.png","alternativeText":"China unicom.png","caption":"China unicom.png","width":722,"height":615,"formats":{"thumbnail":{"name":"thumbnail_China unicom.png","hash":"thumbnail_China_unicom_483a43110d","ext":".png","mime":"image/png","width":183,"height":156,"size":11.99,"path":null,"url":"https://official-media.sphere-ex.com/thumbnail_China_unicom_483a43110d.png"},"small":{"name":"small_China unicom.png","hash":"small_China_unicom_483a43110d","ext":".png","mime":"image/png","width":500,"height":426,"size":46.22,"path":null,"url":"https://official-media.sphere-ex.com/small_China_unicom_483a43110d.png"}},"hash":"China_unicom_483a43110d","ext":".png","mime":"image/png","size":61.21,"url":"https://official-media.sphere-ex.com/China_unicom_483a43110d.png","previewUrl":null,"provider":"strapi-provider-upload-s3-compat","provider_metadata":null,"createdAt":"2022-09-26T06:39:16.946Z","updatedAt":"2022-09-26T06:39:16.946Z"}}},"metaLogo":{"data":{"id":350,"attributes":{"name":"China unicom logo.png","alternativeText":"China unicom logo.png","caption":"China unicom logo.png","width":750,"height":571,"formats":{"thumbnail":{"name":"thumbnail_China unicom logo.png","hash":"thumbnail_China_unicom_logo_2aba6471b9","ext":".png","mime":"image/png","width":205,"height":156,"size":13.18,"path":null,"url":"https://official-media.sphere-ex.com/thumbnail_China_unicom_logo_2aba6471b9.png"},"small":{"name":"small_China unicom logo.png","hash":"small_China_unicom_logo_2aba6471b9","ext":".png","mime":"image/png","width":500,"height":381,"size":31.14,"path":null,"url":"https://official-media.sphere-ex.com/small_China_unicom_logo_2aba6471b9.png"}},"hash":"China_unicom_logo_2aba6471b9","ext":".png","mime":"image/png","size":15.23,"url":"https://official-media.sphere-ex.com/China_unicom_logo_2aba6471b9.png","previewUrl":null,"provider":"strapi-provider-upload-s3-compat","provider_metadata":null,"createdAt":"2022-09-26T08:28:31.851Z","updatedAt":"2022-09-26T08:28:31.851Z"}}},"localizations":{"data":[]}}},"article":{"id":17,"attributes":{"feature":false,"title":"Heterogeneous migration: reducing Dangdang’s customer system RTO 60x and increasing speed by 20%","content":"> [Apache ShardingSphere](https://shardingsphere.apache.org/) helps [Dangdang](https://www.crunchbase.com/organization/dangdang-com) rebuild its customer system with 350 million users, and seamlessly transition from a [PHP](https://www.php.net/)+[SQL Server](https://www.microsoft.com/en-us/sql-server/sql-server-downloads) technology stack to a Java+ShardingSphere+[MySQL](https://www.mysql.com/) stack. The performance, availability, and maintainability of its customer system have been significantly improved, which is the best practice of ShardingSphere’s heterogeneous migration.\n\n## Dangdang’s customer system\nDangdang’s customer system is mainly responsible for account registration, login, and privacy data maintenance. Its previous technology stack was based on PHP and SQL Server, which means a standard centralized architecture, as shown in the figure below.\n![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lorqkp14im9bxbco4yuw.png)\n \n\nBefore the rebuild project started, several business modules of the customer system had encountered multiple problems and technical challenges, such as logical decentralization, low throughput, and high operation & maintenance costs.\n\nTo improve customers’ shopping experience, Dangdang’s technical team decided to optimize the business logic and underlying data architecture to achieve the availability, scalability, and comprehensive improvement of the customer system in multiple scenarios. The rebuild also introduced many technological innovations such as cross-data source double write, read/write splitting, intelligent gateway, and gray release.\n\nDangdang’s technical team completed the system rebuild within half a year, from demand design, sharding planning, logic optimization, and stress testing to its official launch.\n\nThe project used Java to reconstruct more than ten modules, build distributed database solutions through ShardingSphere & MySQL, and finally complete the online migration of heterogeneous databases. The project boasts the following highlights:\n\n- Reconstruct PHP business code using Java language.\n- Replace SQL Server with ShardingSphere & MySQL.\n- Complete online data migration of 350 million users.\n- Complete a seamless launch through the data double-write scheme.\n\n## Pain points & challenges\n\n**Business pain points**\nAt the business level, the registration and login logic of some modules of the customer system was scattered at different ends. This resulted in high maintenance costs, and the old technical architecture was limited in terms of performance improvement and high availability.\n\n- **Maintenance difficulty:** the registration and login logic of multiple platforms is scattered, so business maintenance is complicated.\n- **Limited performance:** the PHP & SQL Server, a centralized technical architecture, had insufficient throughput.\n- **Poor availability and security:** If the active/standby status of SQL Server changes, the subscription database becomes invalid and the reconfiguration takes a window of time. The security of SQL Server running on Windows Server is poor due to viruses, and the upgrading takes a long time (>30min) after the patch is installed.\n\n**Challenges**\n\n- **Data integrity:** the customer system involves data of more than 350 million users. It is necessary to ensure data consistency and integrity after migrating from SQL Server to MySQL.\n- **API transparency:** the API is transparent to the caller to ensure that the caller does not change and to minimize the change of interface.\n- **Seamless switch:** the business system must be seamlessly switched over without impact on business.\n- **Time is short:** the system will be blocked before and after “[618 (aka JD.com Day)](https://edition.cnn.com/2020/06/18/tech/jd-618-china-coronavirus-intl-hnk/index.html) and [11.11 (aka Singles Day)](https://en.wikipedia.org/wiki/Singles%27_Day)” (two online shopping festivals in China), so we need to switch it between the two shopping promotions in a limited window of time, and then undergo the tests to prepare for the 11.11 shopping festival.\n\n## Solutions\n**Overall planning**\nTo improve the maintainability, availability, and performance of the customer system, the R&D team reorganized the customer system architecture.\n\nAt the application layer, the goal was to unify the function logic of all terminals and improve business maintainability.\n\nAt the database layer, the centralized architecture was transformed into a distributed database architecture to improve performance and availability, which is exactly the open-source distributed solution built by ShardingSphere & MySQL.\n\n- **Application layer:** As Dangdang’s overall technology stack changed, its business development language changed from PHP to Java.\n- **Middleware:** As a mature open-source database middleware, ShardingSphere, was used to achieve data sharding.\n- **Database:** Multiple MySQL clusters were used to replace SQL Server databases.\n![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bhrntsoik9fb41raqqbe.png)\n \nThe overall architecture design introduced multiple schemes, such as distributed primary-key generation strategy, shard management, data migration verification, and gray release.\n\n## Distributed primary-key generation strategy\n\nDistributed primary-key generation strategy is the first problem to be solved if database architecture is to be transformed from a centralized architecture to a distributed one based on middleware.\n\nDuring the system rebuild, we chose to build two or more database ID-generating servers. Each server had a `Sequence` table that records the current `ID` of each table. The step size of `ID` that increases in the `Sequence` table is the number of servers. The starting values are staggered so that the ID generation is hashed to each server node.\n\n## Implementing sharding (Apache ShardingSphere）\nDuring the customer system rebuild, database sharding was completed through Apache ShardingSphere, and the read/write splitting function was also enabled.\n\nDue to the requirements of the customer system for high concurrency and low latency, the access end chose [ShardingSphere-JDBC](https://shardingsphere.apache.org/document/current/en/overview/#shardingsphere-jdbc), which is positioned as a lightweight Java framework and provides additional services in Java’s JDBC layer.\n\nIt connects directly to the database via the client and provides services in the form of a `jar` package without additional deployment and dependence. It can be viewed as an enhanced version of the JDBC driver, fully compatible with JDBC and various [ORM](https://www.techopedia.com/definition/24200/object-relational-mapping--orm) frameworks.\n![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6yyoi7xsp7qpayu1it5v.png)\n \n\n**Sharding:** ShardingSphere supports a complete set of sharding algorithms, including `modulo` operation, `hash`, `range`, `time`, and customized algorithms. Customers use the `modulo` sharding algorithm to split large tables.\n**Read-write splitting:** in addition to Sharding, ShardingSphere’s read/write splitting function is also enabled to make full use of [MHA](https://myheroacademia.fandom.com/wiki/Cluster) cluster resources and improve system throughput capacity.\n![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/chx6mgi5yfr2tqv86ho3.png)\n \n\n## Double-write & data synchronization\nData synchronization runs through the whole rebuild project, and the integrity and consistency of data migration are vital to the rebuild.\n\nThis example periodically synchronizes SQL Server’s historical data to MySQL based on Elastic-Job synchronization. During the database switchover, a backup scheme is used to double-write the database to ensure data consistency. The process consists of:\n\n**Step 1:** implement the double-write mechanism\n\nDisconnect link 1, get through links 2, 3, 4, and then 9, 10.\n\n**Step 2:** switch the login service\n\nDisconnect links 9,10, get through link 7 and disconnect link 5.\n\n**Step 3:** switch read service\n\nGet through link 8 and disconnect link 6.\n\n**Step 4:** cancel the double-write mechanism\n\nDisconnect link 2 and complete the switchover.\n![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2f4q20g116681261m9m.png)\n \n\nData verification is performed periodically on both the service side and the database side. Different frequencies are used in different time periods to sample or fully check data integrity. `COUNT/SUM` is also verified on the database side.\n\nCustomer system reconstruction adopts an apollo-based gray release. In the process of new login processing, configuration items are gradually released and sequential cutover within a small range is implemented to ensure the launch success rate. The rebuilt system architecture is shown in the following figure.\n![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iru06ju7apswukev0wxc.png)\n \n\n## Advantages\nAfter the rebuild, the response speed of Dangdang’s customer system is significantly improved, and the daily operation & maintenance costs are also reduced.\n\nThe distributed solution provided by ShardingSphere plays a big part in this. The solution is suitable for various high-traffic Internet platform services, as well as e-commerce platforms and other data-processing systems.\n\n- **Performance improvement:** response speed increased by more than 20%.\n- **High availability:** RTO is reduced to less than 30s owing to the ShardingSphere & MySQL design.\n- **Easy to maintain:** business logic and database maintainability are significantly improved.\n- **Seamless migration:** complete online cutover of each module within 6 months, and window time is zero.\n\n## Conclusion\nThis is ShardingSphere’s second implementation by Dangdang, following the previous one we shared in the post “[Asia’s E-Commerce Giant Dangdang Increases Order Processing Speed by 30% — Saves Over Ten Million in Technology Budget with Apache ShardingSphere](https://shardingsphere.medium.com/asias-e-commerce-giant-dangdang-increases-order-processing-speed-by-30-saves-over-ten-million-113a976e0165)”.\n\nApache ShardingSphere provides strong support for enterprise systems, as the project strives for simplicity and perfection, to achieve simpler business logic and maximum performance.\n\n**Apache ShardingSphere Project Links:**\n\n[ShardingSphere Github](https://github.com/apache/shardingsphere/issues?page=1&q=is%3Aopen+is%3Aissue+label%3A%22project%3A+OpenForce+2022%22)\n\n[ShardingSphere Twitter](https://twitter.com/ShardingSphere)\n\n[ShardingSphere Slack](https://join.slack.com/t/apacheshardingsphere/shared_invite/zt-sbdde7ie-SjDqo9~I4rYcR18bq0SYTg)\n\n[Contributor Guide](https://shardingsphere.apache.org/community/cn/contribute/)","date":"2022-06-21","author":"SphereEx","excerpt":"E-commerce giant DangDang rebuilt its architecture & migrated 350M users with ShardingSphere & MySQL. RTO improved 60x, response speed by 20%, and introduced cross-data source double write, R/W split, and intelligent gateway innovations.","metaDescription":"Dangdang is a B2C-based e-commerce company in China offering a large selection of products both online and offline.","createdAt":"2022-09-26T06:47:46.510Z","updatedAt":"2022-09-27T06:55:21.087Z","publishedAt":"2022-09-27T06:55:21.084Z","locale":"en","caseStudiesType":{"data":{"id":9,"attributes":{"name":"Internet","createdAt":"2022-09-26T10:34:03.086Z","updatedAt":"2022-09-27T06:59:34.838Z","publishedAt":"2022-09-27T06:59:34.836Z","locale":"en"}}},"cover":{"data":{"id":336,"attributes":{"name":"Dangdang.png","alternativeText":"Dangdang.png","caption":"Dangdang.png","width":720,"height":432,"formats":{"thumbnail":{"name":"thumbnail_Dangdang.png","hash":"thumbnail_Dangdang_f80baa2e02","ext":".png","mime":"image/png","width":245,"height":147,"size":11.34,"path":null,"url":"https://official-media.sphere-ex.com/thumbnail_Dangdang_f80baa2e02.png"},"small":{"name":"small_Dangdang.png","hash":"small_Dangdang_f80baa2e02","ext":".png","mime":"image/png","width":500,"height":300,"size":28.45,"path":null,"url":"https://official-media.sphere-ex.com/small_Dangdang_f80baa2e02.png"}},"hash":"Dangdang_f80baa2e02","ext":".png","mime":"image/png","size":37.5,"url":"https://official-media.sphere-ex.com/Dangdang_f80baa2e02.png","previewUrl":null,"provider":"strapi-provider-upload-s3-compat","provider_metadata":null,"createdAt":"2022-09-26T06:48:03.795Z","updatedAt":"2022-09-26T06:48:03.795Z"}}},"metaLogo":{"data":{"id":351,"attributes":{"name":"dangdang logo.jpg","alternativeText":"dangdang logo.jpg","caption":"dangdang logo.jpg","width":500,"height":256,"formats":{"thumbnail":{"name":"thumbnail_dangdang logo.jpg","hash":"thumbnail_dangdang_logo_539787f05a","ext":".jpg","mime":"image/jpeg","width":245,"height":125,"size":5.42,"path":null,"url":"https://sphereex-media-1305704183.cos.ap-beijing.myqcloud.com/thumbnail_dangdang_logo_539787f05a.jpg"}},"hash":"dangdang_logo_539787f05a","ext":".jpg","mime":"image/jpeg","size":12.11,"url":"https://sphereex-media-1305704183.cos.ap-beijing.myqcloud.com/dangdang_logo_539787f05a.jpg","previewUrl":null,"provider":"strapi-provider-upload-s3-compat","provider_metadata":null,"createdAt":"2022-09-26T08:37:49.195Z","updatedAt":"2022-10-12T05:57:41.631Z"}}},"localizations":{"data":[]}}}}},
    "staticQueryHashes": []}