Addispay Financial Services take-home project
Order Processing and Payment System
This project implements an order processing and payment system using Apache Pulsar functions, gRPC, and Docker. The system is designed to handle high-concurrency order requests, process payments, and finalize orders, all in an asynchronous and scalable manner.
Table of Contents
- Overview
- Architecture
- Getting Started
- Directory Structure
- Usage
- Testing
- Deployment
- License
Overview
This system is composed of multiple services:
- gRPC Server: Receives order requests and forwards them to the order processing service.
- Order Processing Service: A Pulsar function that processes incoming orders.
- Payment Processing Service: A Pulsar function that processes payment for the orders.
- Order Finalization Service: A Pulsar function that finalizes the order processing based on payment results.
The services communicate via Apache Pulsar topics, with data being transferred in JSON format between Pulsar functions.
Architecture
The architecture of this system involves several components working together:
- gRPC Client: Submits order requests.
- gRPC Server: Forwards order requests to the order processing system.
- Apache Pulsar: Facilitates messaging between the services.
- Pulsar Functions: Handle core business logic for order processing, payment processing, and order finalization.
Architecture Diagram
For more detail on the undelying architecture, thought processes, things that i learned, and components, see the Architecture document.
Getting Started
Prerequisites
- Docker and Docker Compose installed on your machine.
- Go (1.19 or higher) for local development and testing.
- Pulsar CLI for managing Pulsar functions.
Setup
-
Clone the repository:
git clone https://github.com/dawitel/addispay-project.git
cd order-payment-system
-
Build the Docker images:
cd scripts && ./build.sh
-
Start the services:
cd scripts && ./start.sh
-
Deploy Pulsar functions:
cd scripts && ./deploy_pulsar_functions.sh
Directory Structure
order-payment-system/
├── cmd/
│ ├── grpc_server/
│ └── main.go
├── configs/
│ ├── config.yml
├── docs/
│ ├── architecture.md
| ├── architecture.svg
├── internal/
│ ├── domain/
│ │ ├── models.go
│ ├── grpc/
│ │ ├── order_services.go
│ ├── pulsar/
│ │ ├── order_processor.go
│ │ ├── payment_processor.go
│ │ ├── order_finalizer.go
│ ├── proto/
│ │ ├── order.proto
│ ├── util
│ ├── config.go
│ ├── logger.go
├── scripts/
│ ├── deploy.sh
| ├── start.sh
| ├── stop.sh
| ├── test.sh
| ├── build.sh
| ├── deploy_pulsar_functions.sh
├── test/
│ ├── grpc/
│ │ ├── order_service_test.go
│ ├── pulsar/
│ ├── order_processor_test.go
│ ├── payment_processor_test.go
│ ├── order_finalizer_test.go
├── air.toml
├──.gitignore
├── .goreleaser.yml
├── docker-compose.yml
├── Dockerfile
├── go.mod
├── go.sum
├── LICENSE
├── Makefile
└── README.md
Usage
-
Submit Orders: Use a gRPC client to submit order requests to the gRPC server. The server listens on port 50051.
-
Monitor Services: Check the logs and status of services using docker-compose logs and docker-compose ps.
-
Scaling: Adjust the number of replicas or resources allocated to the services by modifying the docker-compose.yml file.
Testing
To run tests, use the provided test script:
cd scripts && ./test.sh
This script runs unit tests for the gRPC server and Pulsar functions. Ensure that the environment is properly set up before running the tests.
Deployment
-
Build Docker Images:
cd scripts && ./build.sh
-
Push to Docker Registry: Use the deploy.sh script to push Docker images to your registry.
cd scripts && ./deploy.sh
-
Deploy: Deploy the images to your target environment (e.g., Kubernetes, AWS ECS).
License
This project is licensed under the MIT License - see the LICENSE file for details.