闪行生活 · 海外本地生活服务平台建设方案 ShanXing Life · Overseas Local-Life Platform Solution SOLUTION PROPOSAL · BILINGUAL · V1.0
实时切换Instant switch
03
ARCHITECTURE & DEPLOYMENT

技术架构与部署Architecture & Deployment

架构目标只有三个:业务可独立演进、资金绝对可靠、市场可快速复制。因此采用「多端同源 + 领域服务 + 事件驱动 + 复式记账 + 市场配置化」,而不是一次性堆砌微服务。Three goals: independently evolvable domains, absolutely reliable money, and fast market replication. The answer is a shared client codebase, domain services, event-driven integration, double-entry ledger and market configuration.

4.1 总体架构4.1 System overview

flowchart TB
  subgraph CLIENT["客户端 Clients"]
    APPS["用户 / 司机 / 骑手 / 商户 / 股东 App"]
    ADMIN["管理后台 Web"]
  end
  subgraph EDGE["接入层 Edge"]
    GW["API Gateway
鉴权 · 限流 · 灰度"] WS["长连接网关
IM · 轨迹 · 派单"] end subgraph DOMAIN["领域服务 Domain"] ID["账户认证"] ORD["订单中心"] DSP["调度派单"] PAY["支付网关"] LED["结算分账"] end subgraph DATA["数据层 Data"] PG[("PostgreSQL")] RD[("Redis")] MQ[("Kafka")] CH[("ClickHouse")] end subgraph EXT["外部服务 Third party"] ACQ["持牌收单 / 托管"] MAP["Google Maps"] KYC["KYC / 合规"] end APPS --> GW APPS --> WS ADMIN --> GW GW --> ID GW --> ORD WS --> DSP ORD --> DSP ORD --> PAY PAY --> LED ORD --> MQ MQ --> CH LED --> PG LED --> RD DSP --> RD PAY --> ACQ DSP --> MAP ID --> KYC
图 3-1 逻辑架构:端聚合层收敛客户端差异,领域服务独立演进,事件总线连接订单与资金。BFF absorbs client differences, domains evolve independently, and the event bus connects orders and money.

4.2 技术拓扑架构4.2 Technical topology architecture

闪行生活 · 海外本地生活服务平台 技术拓扑架构ShanXing Life · Overseas Local-Life Platform — System Topology Overseas Local-Life Platform · Technical Topology Architecture
六端一体Six ClientsUnified entry
统一 HTTPS 接入Unified HTTPSGateway & auth
模块化后端Modular BackendSpring Boot 3
数据与缓存Data & CachePG · Redis · Kafka
客户公有云部署Public CloudK8s multi-market
安全与审计Security & AuditKYC · audit trail
客户端层ClientLayer 1
用户端 AppPassenger AppiOS · Android
司机端 AppDriver AppiOS · Android
骑手端 AppRider AppiOS · Android
商户端MerchantApp · H5
股东端PartnerApp · H5
管理后台Admin WebReact
统一入口EntryLayer 2
HTTPS / API 网关 · 统一鉴权、限流、灰度与审计HTTPS / API Gateway · Auth, rate limit, canary and auditAuth · Rate Limit · Canary · Audit
长连接网关 · IM、轨迹上报与派单推送Realtime Gateway · IM, tracking and dispatch pushWebSocket · IM · Tracking
业务能力层BusinessLayer 3
账户与认证IdentityKYC · Session
订单与调度Order & DispatchOrder · Dispatch
支付与收款PaymentCashier · Token
商户与商品Merchant & CatalogStore · Menu
履约与轨迹FulfillmentTrip · ETA
报表与对账Report & ReconciliationLedger · Report
消息与通知NotificationInbox · Push
配置与审计Config & Auditi18n · Audit
Java 21 + Spring Boot 3 模块化后端 · Kafka 事件驱动 · 复式记账Java 21 + Spring Boot 3 modular backend · Kafka event-driven · double-entry ledger
数据与
基础设施
Data & Infra
Layer 4
PostgreSQL + PostGISPostgreSQL + PostGISCore data
RedisRedisCache · Session
KafkaKafkaEvents · Replay
ClickHouseClickHouseAnalytics
对象存储Object StorageS3 · Media
第三方与运维Third-party & OpsExternal
地图与导航Maps & NavigationGoogle Maps · Routing · ETA
支付与消息Payment & MessagingCard · Wallet · Local channels · SMS/FCM
身份与合规Identity & ComplianceFace AI · KYC · AML
监控与告警MonitoringTrace · Metric · Log
云与网络Cloud & NetworkK8s · CDN · WAF
数据流向Data FlowLayer 5
客户端ClientsApp · Web
HTTPS
→
统一入口GatewayAuth · Route
RPC
→
业务服务ServicesDomain
SQL
→
数据存储Data StoresPG · Redis
Event
→
监控审计MonitoringTrace · Log
部署边界 / Deployment Boundary:Deployment Boundary: 客户端经 HTTPS 访问统一网关,第三方能力仅在服务端集成,不暴露直连;PostgreSQL 持久化核心交易与资金数据,Redis 缓存会话与轨迹,Kafka 承载事件与补偿;第二市场独立区域部署,仅共享代码与镜像,不共享用户数据。Clients reach the platform only through the HTTPS gateway; third-party capabilities are integrated server-side and never exposed directly. PostgreSQL persists core trade and money data, Redis caches sessions and tracking, Kafka carries events and compensation. A second market deploys an isolated region sharing only code and images, never user data.
图 3-2 技术拓扑:六端经统一入口进入业务能力层,数据与基础设施分层隔离,第三方能力与运维在侧边接入。Technical topology: six clients enter the business layer through one unified gateway, data and infrastructure are layered and isolated, and third-party services plus ops connect on the side.

4.3 技术选型4.3 Technology stack

层 Layer选型 Choice理由 Rationale
客户端ClientsFlutter 五端同源 + React + TypeScript 管理后台Flutter for five apps, React + TypeScript for admin一套业务代码覆盖 iOS / Android,降低六端维护成本;后台沿用 Web 生态便于表格与图表One codebase for iOS and Android; the admin uses the web ecosystem for tables and charts
接入层EdgeKong / APISIX + 自研 BFFKong / APISIX with a custom BFF鉴权、限流、灰度与路由集中;BFF 做端侧字段裁剪,减少移动端流量Centralized auth, rate limiting, canary and routing; BFF trims payloads for mobile
领域服务ServicesJava 21 + Spring Boot 3;Go 用于网关与轨迹Java 21 + Spring Boot 3; Go for gateway and tracking资金与订单强事务用 Java 生态成熟;高并发长连接用 Go 更省资源Mature Java ecosystem for transactional orders and money; Go is leaner for high-concurrency connections
数据DataPostgreSQL 16 + PostGIS、Redis 7、Kafka 3、ClickHouse、S3PostgreSQL 16 + PostGIS, Redis 7, Kafka 3, ClickHouse, S3强一致事务、地理检索、缓存与派单队列、事件回放、分析聚合与对象存储Strong transactions, geospatial search, caching and dispatch queues, event replay, analytics and object storage
搜索SearchOpenSearchOpenSearch门店 / 商品 / POI 检索,支持中文分词与多语言同义词Store, product and POI search with Chinese tokenization and multilingual synonyms
实时通信RealtimeWebSocket 集群;MQTT 为车载设备预留WebSocket cluster; MQTT reserved for in-vehicle devicesIM、派单推送与轨迹上报;MQTT 为硬件接入预留IM, dispatch push and tracking; MQTT reserved for hardware
基础设施InfrastructureKubernetes + Terraform + Argo CD + GitHub ActionsKubernetes + Terraform + Argo CD + GitHub Actions多市场部署、声明式环境、可回滚发布与镜像扫描Multi-market deployment, declarative environments, rollback and image scanning
可观测ObservabilityOpenTelemetry + Prometheus + Grafana + Loki + SentryOpenTelemetry + Prometheus + Grafana + Loki + Sentry统一 trace / metric / log,按订单号与请求号串联Unified traces, metrics and logs correlated by order and request ID

4.4 服务拆分与职责边界4.4 Service decomposition

服务 Service核心职责 Responsibility数据所有权 Owns
identity注册登录、KYC、角色权限、设备与会话Sign-up, login, KYC, roles, devices and sessions用户、身份、角色、会话user, identity, role, session
order下单、状态机、统一订单与子单、售后Ordering, state machine, main/sub orders, after-sales主订单、业务子单、状态日志order_main, sub-orders, status log
dispatch派单评分、扩圈、抢单、司机在线状态、接单限制Scoring, expansion, claiming, driver online state, acceptance limits派单任务、在线状态、分配日志dispatch_task, driver_online, assign_log
fulfillment接驾 / 取餐 / 行程 / 送达状态、轨迹、ETA、偏航告警Pickup, food pickup, trip and delivery states, tracking, ETA, deviation alerts轨迹、配送任务、ETA 快照trip_track, delivery_task, eta_snapshot
catalog门店、商品、库存、菜单、营业状态、核销Stores, products, stock, menus, business status, redemption商户、门店、商品、核销记录merchant, store, product, redeem_record
payment收银台、渠道适配、支付单、退款、拒付Cashier, channel adapters, payment orders, refunds, chargebacks支付单、退款单、渠道流水payment_order, refund_order, channel_txn
ledger规则化分账、复式分录、余额、结算、提现Rule-based split, double entries, balances, settlement, payout规则、分账、分录、钱包、提现split_rule, order_split, ledger_entry, wallet, payout
admin审核、台账、营销配置、系统与多语言、报表Review, ledgers, marketing config, system and i18n, reports审核任务、后台账号、语言资源audit_task, admin_user, i18n_resource
边界原则Boundary rules
服务只写自己的库表,跨域读写一律通过 API 或事件;资金写操作必须幂等且带业务单号;订单状态变更只允许订单服务发起。Each service writes only its own tables; cross-domain access goes through APIs or events. Money writes are idempotent with business numbers. Only the order service mutates order state.

4.5 资金可靠性设计4.5 Money reliability

资金链路的正确性优先于任何性能优化。采用「支付单 → 分账明细 → 复式分录 → 余额快照」四层结构:支付单对接渠道,分账明细记录规则计算结果,分录保证借贷平衡,余额快照用日终快照 + 增量流水双重校验。Correctness outranks performance. The four layers are payment order, split detail, double entry and balance snapshot: channels feed payment orders, split details record rule output, entries keep debits and credits balanced, and snapshots are verified against incremental flows.

幂等Idempotency

所有资金接口以 biz_no 幂等;回调与主动查询双保险。All money APIs are idempotent by biz_no; callbacks and active queries provide dual assurance.

补偿Compensation

本地消息表 + Kafka 保证最终一致;失败重试,超阈值转人工。Outbox plus Kafka for eventual consistency; retries with manual escalation.

余额Balance

余额 = 可用 + 冻结;提现先冻结再出款,失败自动解冻。Balance = available + frozen; payout freezes first and unfreezes on failure.

审计Audit

分录只追加不修改,冲正以反向分录实现,保留操作人与来源单据。Entries are append-only; reversals are new entries; operator and source document are retained.

4.6 部署拓扑与环境4.6 Deployment topology and environments

采用「单区域多可用区起步,市场级隔离扩展」:首城部署在主区域(3 个可用区),数据库主从 + 只读副本;进入第二个国家时新增独立区域,仅共享代码与镜像,不共享用户数据,满足数据驻留要求。Start with a single region across three availability zones, then isolate by market. The first city uses a primary database with replicas; a second country gets its own region sharing only code and images, not user data, to satisfy residency requirements.

计算Compute

K8s 命名空间按域隔离;HPA 按 CPU / QPS / 队列长度扩缩;派单与支付独立资源池。Namespaces per domain; HPA on CPU, QPS and queue depth; dedicated pools for dispatch and payment.

数据Data

PostgreSQL 一主两从 + PITR;按城市分库预留;Kafka 三副本;对象存储跨区复制。Primary plus two replicas with PITR; city-based sharding reserved; three Kafka replicas; cross-region object storage.

网络与安全Network & security

WAF + 网关限流;服务间 mTLS;密钥托管 KMS;生产与办公网隔离。WAF and gateway rate limits; service-to-service mTLS; KMS-managed keys; production isolated from office networks.

环境 Environment用途 Purpose数据 Data发布方式 Release
dev开发联调Development and integration脱敏测试数据Masked test data合并自动部署Auto-deploy on merge
staging验收 / 压测 / UATAcceptance, load test, UAT生产同构、脱敏Production-like, masked按版本发布,需审批Versioned release with approval
production正式运营Live operations真实数据,加密与备份Real data, encrypted and backed up灰度 → 全量,可回滚Canary to full, rollback ready
sandbox支付 / 地图 / KYC 联调Payment, maps and KYC sandbox供应商沙箱Vendor sandbox按需On demand

4.7 安全、合规与性能基线4.7 Security, compliance and performance

支付与隐私Payments & privacy

  • 不落地卡号(PCI SAQ-A)、3DS、令牌化、拒付证据包No card data at rest (PCI SAQ-A), 3DS, tokenization, chargeback evidence
  • GDPR / CCPA / PDPA:同意管理、DSAR、删除与导出GDPR / CCPA / PDPA: consent, DSAR, erasure and export
  • 数据驻留与跨境传输评估Data residency and cross-border transfer assessment

应用与业务合规Application & business compliance

  • OWASP Top 10、依赖扫描、渗透测试、密钥轮换OWASP Top 10, dependency scanning, penetration tests, key rotation
  • 后台 RBAC + 最小权限 + 双因子 + 敏感操作审批RBAC, least privilege, MFA and approvals for sensitive actions
  • 司机资质、保险、税务发票、消费者权益与反洗钱筛查Driver eligibility, insurance, tax invoices, consumer rights and AML screening
场景 Scenario目标 Target说明 Note
接口 P95(读)API P95 (read)< 200 ms门店列表、订单详情、钱包查询Store list, order detail, wallet query
接口 P95(写)API P95 (write)< 400 ms下单、支付回调、接单Ordering, payment callback, acceptance
派单下发Dispatch push< 3 s下单到司机端收到派单Order to driver offer received
轨迹上报Tracking5 s / 次interval支持 1 秒加密1-second mode supported
系统可用性Availability99.95%资金与订单链路,年停机 < 4.4 小时Money and order paths; under 4.4 hours downtime per year
单城容量City capacity5,000 / 日day峰值按 10 倍冗余设计Designed for 10× peak

4.8 多语言与多币种实现4.8 i18n and multi-currency

语言包Language packs

i18n_resource(key, locale, value, status);后台缺失词条看板、批量导入导出、发布版本与回滚;App 内置兜底文案防止空白。i18n_resource(key, locale, value, status); missing-key dashboard, bulk import/export, versioned publishing and rollback; built-in fallbacks prevent blanks.

金额与汇率Amounts & FX

金额统一 numeric(18,4) + currency;下单写 fx_rate_snapshot;分账与结算按订单币种,跨币种另记折算分录。All amounts numeric(18,4) plus currency; FX snapshot at order time; split and settlement in order currency, with separate conversion entries.

RTL 与本地化细节RTL and localization details
若进入阿拉伯语市场,布局需支持 RTL 镜像、数字与日期本地化、姓名与地址结构差异、宗教节日与营业时间差异。建议一期即预留 RTL 开关与双向文本组件。For Arabic markets, plan RTL mirroring, localized numerals and dates, different name/address structures and holiday-aware hours. Reserve an RTL switch and bidirectional text components in phase 1.