济南模型公司
  • 济南市市中区
  • 经十西路6288号1号楼101室
  • 电话:0531-55504101
  • 网站:http://www.jnsymx.com
  • 手机:18660800958 13869134430
新闻中心当前位置:首页-新闻中心
    12306的核心模型设计思路到底复杂在哪里
    2018-2-15 9:09:28 来源:http://www.jnsymx.com
    元宵节结束,年就真的过完了。挥别故里,回到打拼的城市,理性思维是否也跟着工作状态一起回归了呢?每一年的春运都是对12306的一次大考,抛去盲从和偏见,让我们用工程师的思维重新打量、从业务分析的角度去探讨,12306的核心模型设计思路和架构设计到底复杂在哪里?
    The Lantern Festival is over, and the year is really over. Say goodbye to the hard work of the city, hometown, rational thinking is also followed the working state of the back? Every year, the Spring Festival is a big test of 12306, thrown blindly and prejudice, let us use the engineer's thinking, re looked at from the business perspective to explore the core model design and architecture design of the complex 12306 exactly where?
    春节期间,无意中看到一篇文章,文章中讲到12306的业务复杂度远远比淘宝天猫这种电商网站要复杂。后来自己想想,也确实如此。所以,很想挑战一下12306这个系统的核心领域模型的设计。一般的电商网站,购买都是基于商品的概念,每个商品有一定量的库存,用户的购买行为是针对商品的。当用户发起购买行为时,系统只需要生成订单并对用户要购买的商品减库存即可。但是,12306就不是那么简单了,具体复杂在哪里,我下面会进一步分析。
    During the Spring Festival, I unwittingly read an article in which 12306 of the business complexity is far more complex than the Taobao Tmall website. Then think about it, and that's true. So, I'd like to challenge the design of the core domain model of the 12306 system. The general e-commerce website, the purchase is based on the concept of commodity, each commodity has a certain amount of inventory, the user's purchase behavior is aimed at the goods. When the user initiates the purchase behavior, the system only needs to generate an order and reduce the inventory of the goods to be purchased by the user. But, 12306 is not so simple, the specific complexity where, I will further analyze the following.
    另外一个让我写这篇文章的原因,是我发现也许是否是因为目前12306的核心领域模型设计的不够好,导致用户购票时要处理的业务逻辑异常复杂,维护数据一致性的难度也几百倍的上升,同时面对高并发的订票也难以支持很高的TPS。
    Another let me write this article, I found that perhaps is because the current design model of the 12306 core areas is not good enough, causing the user to purchase the business logic processing is very complex, the rise of maintaining data consistency is also hundreds of times, and the surface of high concurrent booking is also difficult to support very high TPS.
    技术人员往往更注重技术层面的解决方案,比如一上来就分析如何集群、如何负载均衡、如何排队、如何分库分表、如何用锁,如何用缓存等技术问题,而忽略了根本的业务层面的思考,如分析业务、领域建模。

    Technical personnel often pay more attention to technical solutions, such as to how to analyze how to cluster, load balancing, how to queue, how to split table, how to use the lock, how to use the cache and other technical problems, while ignoring the thinking the most fundamental aspect of business, such as business analysis, domain modeling.

    模型设计
    model design
    传统电商的思路
    Ideas of traditional e-commerce
    如果按照普通电商的思路,把票(站点区间)设计为商品(聚合根),然后为票设计库存数量。我个人觉得是很糟糕的。因为一方面这种聚合根非常多(上面的G71就有408个);另一方面,即便枚举出来了,一次购票也一定会影响非常多其他聚合根的库存数量(只要被部分或全部重叠的区间都受影响)。这样的一次订单处理的复杂度是难以评估的。而且这么多聚合根的更新要在一个事务里,这不是为难数据库吗?而且,这种设计必然带来大量的事务的并发冲突,很可能导致数据库死锁。
    If in accordance with the common business idea, the ticket (site interval) is designed as a commodity (Ju Hegen), and then the number of tickets for the design of the ticket. I personally think it's very bad. Because on the one hand, the root of this polymerization is very large (there are 408 G71 on the top); on the other hand, even if enumerated, a ticket purchase will also affect the number of other aggregated roots (as long as part or all overlapping intervals are affected). The complexity of such an order processing is difficult to evaluate. And so many aggregated roots are updated in one transaction, is this not a difficult database? Moreover, this design inevitably brings a lot of transaction concurrency conflicts, which may lead to database deadlock.
    总之,我认为这种是典型的由于领域模型的设计错误,导致并发冲突高、数据持久化落地困难。或者如果要解决并发问题,只能排队单线程处理,但是仍然解决不了要在一个事务里修改大量聚合根的尴尬局面。
    In a word, I think this is a typical design error of the domain model, which leads to high concurrency conflicts and difficult data persistence. Or if we want to solve concurrent problems, we can only queue up for single thread processing, but still can not solve the embarrassing situation that we need to modify a large number of aggregate roots in a transaction.
    听说12306是采用了Pivotal Gemfire这种高大上的内存数据库,我对这个不太了解。我不可想象要是不使用内存数据库,他们要怎么实现车次内的票之间的数据强一致性(就是保证所有出售的票都是符合上面讨论的业务规则的)?所以,这种设计,我个人认为是思维定势了,把火车票看成是普通电商的商品来看待。所以,我们有时做设计又要依赖于经验,又要不能被以往经验所束缚,真的不容易,关键还是要根据具体的业务场景多多深入分析,尽量分析抽象出问题的本质出来,这样才能对症下药。那是否有其他的设计思路呢?
    I heard that 12306 is the large memory database that uses Pivotal Gemfire, which I don't know much about. I can't imagine if they don't use the memory database, how do they achieve strong consistency between the tickets in the train trips (that is to say that all the tickets sold are in line with the business rules discussed above)? So, this kind of design, I personally think it is the thought setting, regard train ticket as the commodity of the ordinary electric business. Therefore, we sometimes design and rely on experience, and cannot be bound by past experience. It's really not easy. The key is to analyze more deeply according to the specific business scenarios, and try to analyze the essence of the abstract problems, so as to suit the remedy to the case. Does that have any other design ideas?
    本文由东营模型公司友情奉献,更多有关的知识请点击:http://www.jnsymx.com我们将用先进的技术,真诚的态度,为您提供为全面的服务。我们将会陆续向大家奉献,敬请期待。
    This article is based on the friendship and dedication of Dongying model company, and more related knowledge, please click: http://www.jnsymx.com, we will provide you with the most advanced technology and the most sincere attitude to provide you with the most comprehensive service. We will continue to contribute to you and look forward to it.
    版权所有:济南市槐荫区视野模型设计制作中心 Copyright @ 2011-2012 电话:18660800958  传真:0531-55504101 鲁ICP备11014722号 地址:济南市市中区经十西路6288号1号楼101室 
    网址:http://www.jnsymx.com