1 Star 0 Fork 508

若凡 / 12306

forked from nageoffer / 12306 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

什么是 12306?

🧐 为什么 12306 铁路购票项目更适合校招?

12306 铁路购票服务是与大家生活和出行相关的关键系统,包括会员、购票、订单、支付和网关等服务。

这个项目旨在让学习者可以快速掌握分布式系统设计的技巧,尤其适合对高并发、分布式感兴趣的同学学习。如果想深入理解和应用分布式系统的设计原则,这个项目将会是一个很好的学习资源。

如果对开源感兴趣,可以关注马哥的中间件项目:动态线程池框架 Hippo4j。6.2kStar,43家企业使用。

有几位同学参与 Hippo4j 的贡献后,将这段经历写到了简历上,都拿了不错的大厂offer。

12306 项目中包含了缓存、消息队列、分库分表、设计模式等代码,通过这些代码可以全面了解分布式系统的核心知识点。

为了方便大家学习,该系统提供了两种独立版本:

  • SpringBoot 聚合服务版本:适合测试和部署,可以直接启动 aggregation-service 聚合服务和网关服务。

  • SpringCloud 微服务版本:适合学习微服务设计,可以分别启动支付、订单、用户、购票和网关服务。

根据自己的学习和使用需求,选择合适的版本启动即可。微服务版本侧重学习设计,聚合服务版本侧重测试和部署。请根据场景需要,选择正确的版本进行学习和使用。

拿个offer 组织项目

组织简介:拿个offer - 开源&项目实战,🚀 助力你在校招或社招上拿个offer。

目前组织下已有业务、基础架构以及中间件等多种类型项目,代码完全开源!项目列表如下:

Project Gitee GitHub Intro
Hippo4j star 异步线程池框架,支持线程池动态变更&监控&报警
12306 star 完成高仿铁路 12306系统,帮助学生主打就业的项目
CongoMall star 企业级 TOC 商城,基于 DDD 领域驱动模型开发
Seraph star 幂等基础组件,接口幂等和消息队列重复消费解决方案

技术架构

在系统设计中,采用最新 JDK17 + SpringBoot3&SpringCloud 微服务架构,构建高并发、大数据量下仍然能提供高效可靠的 12306 购票服务。

通过学习 12306 项目,不仅能了解其运作机制,还能接触最新技术体系带来的新特性,从而拓展技术视野并提升自身技术水平。

下方的架构图全面描述了项目的服务集合、组件库列表和基础设置层等要素,有助于用户快速了解 12306 平台的顶层设计和业务细节,从零到一进行构建。

加群沟通

开源不易,右上角点个 Star 鼓励一下吧!

如果大家想要实时关注 12306 更新的文章以及分享的干货的话,可以关注我的公众号:马丁玩编程

使用过程中有任何问题,或者对项目有什么建议,添加好友备注:12306,领取项目学习资料,和 2000+ 志同道合的朋友交流讨论。

项目质量怎么样?

我理解大家对选择一个合适的项目以投入时间和精力的担忧。选对项目既可以锻炼技能,又可以产出价值是非常重要的。

以用户服务系统为例,低并发和低数据量的系统相对简单,但高并发和海量数据的系统则需要考虑很多额外因素。

  1. 当用户在 12306 网站注册新账号或添加乘车人时,系统需验证用户提交信息的真实性和准确性。如何有效预防用户提交虚假信息,保障系统购票的安全?
  2. 12306 的大规模用户和乘车人数据如何选择分库分表?选择哪个字段作为分片键?如何在老业务上平滑上线分库分表?出现问题如何快速回滚?
  3. 系统支持会员使用用户名、手机号以及邮箱等多种方式进行登录。由于登录时无法确定用户的分片键,造成的“读请求扩散”问题如何解决?
  4. 在高并发的会员注册场景下,绝对会出现缓存穿透问题。网上鼓吹的对不存在 Key 进行缓存值设为 Null,以及布隆过滤器等都存在漏洞,如何解决?
  5. 存在较多的敏感信息,比如会员或者乘车人的姓名、手机号、邮箱、证件号码以及住址,如何防止数据库被攻击时造成的敏感信息泄露?

再以购票服务为例,当用户购买两个乘车人的高铁一等座票且没有选座时,座位的分配逻辑如下:

  1. 首先检查当前列车的一等座余票是否足够。如果余票不足,直接向客户端返回购票请求失败的响应;
  2. 获取所有车厢中有两个座位余票的车厢,并对这些车厢进行遍历,按照下述流程执行;
  3. 首先检查所有车厢中是否存在一等座车票的相邻座位。如果所有车厢中都没有相邻座位,进入下一步逻辑;
  4. 接着检查是否有车厢中包含两个不相邻的一等座座位?因为同车厢两座位相邻座位没有的话,就退而找同车厢不相邻座位;
  5. 如果以上逻辑都无法满足,那么最后选择分配不同车厢的不相邻座位。这种情况下,由于已经确认一等座的余票充足,因此一定能够成功完成购票;
  6. 通过以上步骤,购票系统能够在高铁一等座票余票充足的情况下,合理地分配座位,确保乘车人出行时有良好的座位体验。同时,如果余票不足,系统会优先满足乘车人顺利购票的需求。

如何使用

12306 前端系统实现了与官网极为接近的业务逻辑和 UI 展示。

在学习过程中,通过类似官网的前端系统直接调试后端服务,可以避免纯通过接口测试的繁琐。这种真实场景的模拟,使得学习过程更加流畅高效。

目前前端系统还在开发中,部分业务及细节处还在调整,完成后统一给出控制台操作手册,请耐心等待。

1. 车票查询功能

2. 提交订单页,选择乘车人下单

3. 高铁在线选座页面

12306 购票误区

说些大家对于 12306 购票时没有考虑到的一些业务点,或者存在误区的地方。

背景:假设,有一站列车,途径北京南、济南西、南京南、杭州东。

查询站点对应的列车车次信息。

  • 你以为:通过搜索引擎技术 ElasticSearch 技术解决,因为涉及大量的查询条件。比如:车次、车组、出发车站、到达车站、出发时间等。
  • 实际上 :当海量并发查询时,ElasticSearch 的并发能力以及资源占用情况来说,并不适用。而且,大家如果仔细思考,发现这些查询条件都是可以通过类似于 Redis 的缓存技术存储,并在内存中进行组装。

买一张北京南到南京南的车票。

  • 你以为:只扣减北京南到南京南单趟的票。
  • 实际上:会扣减北京南-济南西,北京南-南京南,济南西-南京南的三趟车票。如果其中有任意条件不满足都不会购买成功。

买一张济南西到南京南的车票。

  • 你以为:按照上述逻辑,如果通过软件恶意刷票,只买济南西-南京南的票,北京南-杭州东是否就买不到了?
  • 实际上:每个站数之间的数量都有规则。虽然放票时间都是一致的,但是优先大站之间的票量,避免因为大量用户购买了中间站的车票导致始发站和终点站的购票困难。该问题通过动态放票解决,比如刚开始放票时对小站之间仅开放少量票,大站之间放出来多数票。如果后续接近发车时间,再开放小站间的车票。

当然,业务以及技术上的难点和亮点并不止于这些,更多的信息可以通过代码以及 12306 的使用上进行发掘。

常见问题答疑

Q:面向人群是学生,但是里面这么多的代码设计方案,学生能看明白么?

A:文档中准备了两部分资料,一部分是讲解技术实现细节,通过该部分可以很好掌握核心技术;另一部分是讲如何从零到一实现系统;通过两种文档结合,可以很好吸收 12306 系统中的设计。

Q:如何把 12306 项目写到我的简历上?

A:马哥在文档库最后给大家提供了 12306 写到简历上的亮点、难点以及解决方案。其次,通过 12306 去面试的小伙伴的面试题也会进行汇总,免费供大家学习使用。

Q:工作几年的有必要看 12306 这个系统么?

A:我觉得有必要,已经工作的同学虽然没办法把这个项目应用到简历上,但是系统中好的设计却是可以代入到自己的项目中,提高自己项目的亮点以及难点。

项目文档

共计 100+ 核心技术文档!帮助你深入了解以及快手上手 12306 系统。

项目中的文档包括三部分,快速开始、核心技术文档以及从零到一开发。可根据自己的兴趣选择深入了解核心技术或从零到一复刻系统。

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (properties) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

🔥 官方推荐 🔥 大学春招、秋招、应届项目,SpringBoot3 + Java17 + SpringCloud Alibaba + Vue3 等技术架构,完成高仿铁路 12306 用户 + 抢票 + 订单 + 支付服务,帮助学生主打就业的项目。 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/ruofanwei/12306.git
git@gitee.com:ruofanwei/12306.git
ruofanwei
12306
12306
main

搜索帮助