Payment Microservice - Hexagonal Architecture Implementation

Developed a payment microservice using Python FastAPI with hexagonal architecture (ports and adapters pattern). This project demonstrates clean architecture principles with clear separation between domain logic, infrastructure adapters, and external integrations, featuring PostgreSQL persistence and Docker containerization.

August 2025
Duration: 2 weeks
Client: TiketQ Platform
PythonFastAPISQLAlchemyPostgreSQLDockerDocker ComposeHexagonal ArchitectureDomain-Driven DesignRepository Pattern
View Code
Payment Microservice - Hexagonal Architecture Implementation - Image 1
1 / 4
Fit

Background

The goal of this project was to build a maintainable and scalable payment microservice following hexagonal architecture principles. The focus was on creating a system where business logic is completely isolated from external concerns, making it easily testable and adaptable to different infrastructure requirements.

Strategy & Solution

  • Implement hexagonal architecture with clear ports (interfaces) and adapters (implementations) separation.
  • Design domain models that are framework-agnostic and contain pure business logic.
  • Create repository interfaces that can be implemented by different storage adapters (PostgreSQL, in-memory, etc.).
  • Use dependency injection to maintain loose coupling between layers and enable easy testing and configuration changes.

Responsibilities & Scope

  • Architected the payment service using hexagonal architecture with domain models, repository ports, and database adapters.
  • Implemented the DatabaseAdapter as a secondary adapter that translates domain operations to PostgreSQL operations.
  • Designed comprehensive payment record management with support for multiple payment methods and status tracking.
  • Created robust error handling and transaction management using SQLAlchemy ORM with proper connection pooling.
  • Configured Docker secrets integration for secure database credential management in containerized environments.

Results & Impact

  • Successfully implemented hexagonal architecture that completely isolates business logic from infrastructure concerns.
  • Created a flexible payment system supporting multiple payment methods (Credit Card, Bank Transfer, E-Wallet, QRIS) through domain models.
  • Achieved database connection reliability through proper connection pooling and health check mechanisms.
  • Implemented comprehensive metadata handling for payment gateway integrations with JSON serialization support.
  • Designed scalable database schema with optimized indexing for payment lookups and order associations.

© 2025 Satria Wira Bakti.