From a Small Go Module to Enterprise Fintech

DDD & Code Architecture in Practice

คอร์สสำหรับ engineer ที่ต้องเปลี่ยน Domain-Driven Design จากศัพท์และ diagram ให้เป็นการตัดสินใจใน codebase จริง เริ่มจาก Ubiquitous Language, Subdomain และ Bounded Context แล้วค่อยเลือก Transaction Script, Layered Architecture, Rich Domain Model หรือ Ports & Adapters ให้เหมาะกับแต่ละ module พร้อมตัวอย่าง Go จากระบบ Fintech ระดับองค์กร

25 บทเรียน5 partsArchitecture

Course trail

เส้นทางการเรียน

Part 1 — Architecture Starts with the Domain

Part 2 — Choosing Code Architecture

Part 3 — Organizing the Codebase

Part 4 — Boundaries, Data and Integration

Part 5 — Enterprise Fintech Architecture

วิธีอ่านคอร์สนี้

คอร์สนี้ไม่ได้เริ่มจากการสร้างโฟลเดอร์ domain, application และ infrastructure แต่เริ่มจากการหาว่า ธุรกิจกำลังแก้ปัญหาอะไร ใช้ภาษาอะไร มีกฎใดห้ามผิด และใครเป็นเจ้าของการเปลี่ยนแปลงนั้น เมื่อคำตอบเหล่านี้ชัด เราจึงค่อยเลือก code architecture ที่มีต้นทุนเหมาะกับปัญหา

  • Part 1 สร้าง vocabulary และ boundary ระดับ Strategic DDD
  • Part 2 เปรียบเทียบ Transaction Script, Layered Architecture, Rich Domain Model และ Ports & Adapters จากแรงที่เกิดขึ้นจริง
  • Part 3 เปลี่ยนการตัดสินใจเป็น Go package และ folder structure ตั้งแต่ codebase เล็ก ไปจนถึง Billing ที่มีหลาย module
  • Part 4 ลงมือออกแบบ database, cache, Payment Gateway, authentication, authorization, webhook และ workflow ที่ข้าม boundary
  • Part 5 รวม Wallet, Checkout, Billing, Payment Integration และ Web Portal เป็น enterprise Fintech case study

สถานะการเผยแพร่

คอร์สนี้เขียนครบ 5 Parts รวม 25 Chapters แล้ว ทุกบทผ่าน content check, build และ browser rendering เมนูจึงแสดงครบตั้งแต่ Domain discovery ไปจนถึง enterprise Fintech capstone โดยไม่มีบท placeholder

สิ่งที่คอร์สนี้ต้องการให้คุณทำได้

เมื่อเรียนจบ คุณควรอธิบายได้ว่าเหตุใด module หนึ่งใช้ Transaction Script แต่อีก module ใช้ Rich Domain Model และเหตุใดการมี Bounded Context ไม่ได้แปลว่า ต้องแยก microservice ทันที คุณควรออกแบบ consumer-owned port สำหรับ database หรือ external provider ได้โดยไม่ให้ vendor DTO รั่วเข้า business model และรู้ว่า authentication, use-case authorization, resource ownership กับ domain invariant เป็นคนละความรับผิดชอบ

ตัวอย่างใช้ภาษา Go แต่เป้าหมายคือทักษะการตัดสินใจ ไม่ใช่การจำ template ผู้อ่านควรคุ้นเคยกับ HTTP API, relational database และการเขียน backend service มาก่อน ไม่จำเป็นต้องเคยทำ DDD

Running Case Study

เราจะค่อย ๆ วิเคราะห์ platform สมมติของบริษัท Fintech แห่งหนึ่ง:

Areaคำถามที่ใช้ค้นหา boundary
Walletใครเป็นเจ้าของ account, ledger, transfer และกฎของ balance
Checkoutcheckout session กับ payment attempt มี lifecycle อย่างไร
Billingsubscription, usage, invoice, credit note, receivable และ receipt ควรแบ่งอย่างไร
Payment Integrationapplication จะคุยกับ provider โดยไม่ผูก domain กับ vendor ได้อย่างไร
Web Portalเป็นเพียง channel/BFF หรือมี business capability ที่เป็นของตัวเอง

รายชื่อนี้เป็น สมมติฐานเริ่มต้น ไม่ใช่คำตอบว่าแต่ละกล่องคือ Bounded Context บทเรียนจะใช้ language, invariant, lifecycle, data ownership และ change pattern เป็นหลักฐานในการยืนยันหรือแก้ boundary

Technology Is Evidence, Not the Curriculum

  • ใช้ MySQL แสดง authoritative persistence, transaction, constraint, concurrency และ repository integration test
  • ใช้ Redis แสดง derived state, cache, read model, TTL และ invalidation
  • ใช้เอกสารทางการของ Stripe เป็นตัวอย่าง payment lifecycle, integer minor unit, idempotency, ambiguous failure และ webhook delivery
  • ใช้ PaymentGateway เป็น application-owned abstraction โดยไม่สร้างบท “Implementing Stripe Adapter” หรือผูก architecture กับ vendor รายเดียว
  • อ้าง Temporal เมื่อจำเป็นต้องอธิบาย orchestration boundary ส่วนรายละเอียด SDK อยู่ในคอร์ส Temporal for Fintech

Authoritative state กับ display state

Redis หรือ composed read model อาจเหมาะกับหน้าจอที่ยอมรับข้อมูลเก่าได้ แต่การอนุมัติ Transfer, Refund หรือการตัดสินใจที่เปลี่ยนเงินต้องอ่านจาก authoritative state และตรวจ invariant ภายใน boundary ที่เป็นเจ้าของกฎ การเลือกแหล่งข้อมูลต้องถูกระบุเป็นส่วนหนึ่งของ use-case contract

Evidence Labels

คอร์สแยกข้อความสำคัญเป็น 3 ชนิด:

  1. Definition/Pattern — อ้างต้นทาง เช่น Eric Evans, Martin Fowler หรือ Alistair Cockburn
  2. Heuristic/Trade-off — บอกเงื่อนไข ข้อยกเว้น และสัญญาณที่ควรทบทวน
  3. Course Convention — รูปแบบที่เลือกเพื่อให้ตัวอย่าง Go สม่ำเสมอ แต่ไม่อ้างว่าเป็นมาตรฐานสากล

ตารางอย่าง Core → Rich Domain Model จึงใช้เป็นจุดเริ่มสนทนา ไม่ใช่สูตรสำเร็จ Core หมายถึงความได้เปรียบของธุรกิจ ขณะที่ operational criticality, security, compliance และ consistency เป็นอีกชุดแรงที่ต้องพิจารณาแยกกัน

Business policy ต้องมีเจ้าของ

เพดานธุรกรรม, KYC threshold, maker-checker rule, retention period และข้อกำหนด compliance ต้องมาจากเจ้าของที่รับผิดชอบหรือ regulator พร้อมชื่อ เอกสาร และวันที่ ตัวอย่างในคอร์สมีไว้สอนตำแหน่งของ policy ใน architecture ไม่ใช่กำหนด policy ให้ระบบจริง และการใช้ pattern ใดไม่ได้ทำให้ระบบ “ผ่าน PDPA/PCI” โดยอัตโนมัติ

Reading Backbone

แต่ละบทจะเพิ่ม primary source ที่เกี่ยวข้องกับ claim ของบทนั้นโดยตรง