EEC e-Customs
The customs-privilege e-service for Thailand’s Eastern Economic Corridor: companies submit machinery and raw-material imports, BOQs, fast-track releases and e-payments; officers review and approve.
- Role
- Senior engineer · bootstrapped 5 Phase 2 services · main author of the payment service · MR reviewer for a ~10-person team
- Stack
- .NET 10 · CQRS · Next.js 16 · PostgreSQL 17
- Problem
- Phase 2 re-architected Phase 1 into microservices, and had to talk to outside systems — DGA digital signatures and the asynchronous NSW customs gateway.
- What I did
- Bootstrapped five Phase 2 services from the first commit, wrote most of the payment service, review and approve the team’s MRs, and built across the web app and core service.
Results
Apr → Nov 2026 · Phase 2 signed off in SIT/UAT, awaiting launch · bootstrapped 5 services · 79% of payment-service commits- In SIT/UAT, retrying a payment returns the existing payment link instead of charging twice, and document numbers no longer collide under load
- Adding a scheduled job is quicker — no queue listener to build in every service — and jobs can only call approved services
- Every UAT round re-runs a 275-case Playwright suite; the payment service alone has about 250 unit tests
How it fits together
Redrawn diagramHow it works
- 01
Slow outside systems
One external service is the only door out: DGA is called synchronously; NSW goes through RabbitMQ with polling for the answer.
- 02
Work on a schedule
A schedule service runs Hangfire jobs as internal commands or HTTP callbacks.
- 03
Certificates you can trust
Certificate PDFs are rendered by Qorstack Report through Gotenberg.
What went wrong — and how I fixed it
Real problems from the commit history, not a highlight reel.
- 01Problem
Retrying a payment could create a second payment.
How I fixed itReturn the existing payment link when one is active, and guard state transitions so a webhook can’t overwrite a cancelled request.
- 02Problem
Scheduled jobs replied over a queue, so every service needed its own consumer.
How I fixed itHangfire calls services back over HTTP, with an exact-host allow-list (SSRF protection) and callback authentication.
- 03Problem
Notifications succeeded on some channels and failed on others.
How I fixed itA bounded retry queue with dead-lettering, and delivery logs so retries skip channels that already succeeded.
- 04Problem
Running numbers collided under concurrency.
How I fixed itA transaction-scoped PostgreSQL advisory lock around count-then-insert.
- 05Problem
Stale cache, cleared by hand with key prefixes.
How I fixed itA save interceptor that clears tagged Redis entries only after commit, covering 57 cached queries.
Decisions & trade-offs
CQRS inside Clean Architecture
Commands and queries split with MediatR, validated with FluentValidation — the same shape in every service, so people move between them easily.
GitOps for ~14 workloads
Kustomize and Fleet make every deploy reviewable in git.
- Five Phase 2 services bootstrapped (payment, scheduling, workers, reports, integrations)
- Most of the payment service: idempotency, callback checks, expiry, audit trail
- Advisory-lock standard for document numbers, adopted by five teammates
- Sage AI-agent rules and decision records across the repos
- MR review and approval for the team; the 275-case Playwright UAT suite
- Features across the Next.js 16 web app and .NET 10 core service
- .NET 10
- CQRS
- Next.js 16
- PostgreSQL 17
- Redis
- RabbitMQ
- MinIO
- Hangfire
- OpenTelemetry
- Kubernetes
Client system with private data — the visuals on this page are redrawn diagrams, not screenshots.