如何设计一套支付系统
支付永远是一个公司的核心领域,因为这是一个有交易属性公司的命脉。那么,支付系统到底长什么样,又是怎么运行交互的呢?抛开带有支付牌照的金融公司的支付架构,下述链路和系统组成基本上符合绝大多数支付场景。其实整体可以看成是交易核心+支付核心 两个大系统。交易系统关联了业务场景和底层支付,而支付系统完成了调用支付工具到对账清算等一系列相关操作。下面我们就来一起看下各个系统的核心组成和交互。
1. 支付系统总览
核心系统交互

业务图谱

2. 核心系统解析
交易核心
交易核心把公司的业务系统和底层支付关联起来,让业务系统专注于业务,不比关心底层支付。
交易核心

基础交易类型抽象

多表聚合 & 订单关联

支付核心
支付核心主要负责将多种支付类型进行抽象,变成充值
、提现
、退款
、转账
四种支付形态。同时,还要负责集成多种支付工具,对支付指令进行编排等等。
支付核心总览

支付行为编排
其目的,是实现插件式开发
、支付规则可配置
的 灵活开发方式。

异常处理
异常处理包括了 重复支付、部分支付、金额不一致、其他异常等异常场景。

渠道网关

资金核算

3. 服务治理
平台统一上下文
通过确定系统边界、业务建模拆分之后,整个支付平台被拆分几十个服务,而如何保障在服务间流转业务信息不被丢失,是我们需要考虑的问题。平台统一上下文的要素信息(唯一业务标识码),在整个支付平台链路中全程传递,被用来解决这个问题。

数据一致性治理
大型的支付公司,内部都有非常严格和完备的数据一致性方案,比如采用业务侵入性非常大的分布式事务等,以牺牲开发效率来提升数据的稳定,是非常有必要的。而业务公司,如果不采用分布式事务又有哪些应对策略呢?
CAS校验

幂等 & 异常补偿

对账

准实时对账

DB拆分

异步化
支付是整个交易链路的核心环节,那么,怎么兼顾支付系统的稳定性和执行效率呢?是异步化。
消息异步化

外部支付调用异步化

在外部支付中,经常需要服务方与第三方支付交互,获取预支付凭证,如上图所示。
这种同步调用的情况下,由于需要跨外部网络,响应的 RT 会非常长,可能会出现跨秒的情况。由于是同步调用,会阻塞整个支付链路。一旦 RT 很长且 QPS 比较大的情况下,服务会整体 hold 住,甚至会出现拒绝服务的情况。

因此,可以拆分获取凭证的操作,通过独立网关渠道前置服务,将获取的方式异步化,从前置网关获取内部凭证,然后由前置网关去异步调用第三方。
异步并行化

资金核算异步化

热点账户账务单独处理

记账事务切分

4. 生产实践
性能压测
构建压测模型,模拟现实真实场景;压测数据进影子库,正常业务无侵入;单机性能和集权链路都不能忽视;识别系统稳定性和容量配比。。。

稳定性治理

核心链路分离

服务依赖降级

作者:PetterLiu
本文来自博客园,作者:古道轻风,转载请注明原文链接:https://www.cnblogs.com/88223100/p/How-to-design-a-payment-system.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
2021-04-05 KVM/QEMU/qemu-kvm/libvirt 概念全解
2020-04-05 常用的MySQL优化操作
2020-04-05 SQL Server 2012自动标识列值跳转问题