A system for managing customers and their purchased items, demonstrates distributed, data oriented design.
** In the actual configuration some services that should be private are currently exposed to the host machine for debugging purposes
-
customer-bff-service
- A client-facing web server, serves a specfiic frontend, for example a mobile application. It exposes a REST API and is a Kafka Producer. When deployed, this service is reachable from outside the container network on port 5000. -
customer-management-service
- The system's core service, manages the entities of the system in a relational database using SQLAlchemy. It exposes an internal REST API, interacts with the database using SQLAlchemy ORM and consumes messages from "purchases" topic. In dev stage, the service seeds it's own data for testing purposes. When deployed, it is not exposed to requests from outside the container network. -
Kafka Broker
- A Pub-Sub system messaging system for data streaming, processing and async communication. -
Zookeeper
- Provides state management for Kafka -
CustomerDB
- PostgreSQL -
Airflow
- A task management platform for developing, scheduling and monitoring batch-oriented workflows. Deployed separately from the other components (as it consists of 7 containers). loads a "calc_total_spent" DAG that periodically updates the database with customers' total spent sum. -
Grafana
- A monitoring platform for datasources. Displays the calculated data fromcustomer_total_spent
-
customer-frontend
- A simple react application that allows for purchasing and viewing purchased items, deployed independently.
To Deploy the platoform, only docker is required:
- Clone this repository
- A a bridge network is required for communication with airflow later on:
docker network create customer-airflow-bridge
- Run the docker-compose file (with DOCKER_DEFAULT_PLATFORM is set to amd64 in case you're running an ARM CPU):
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose up -d --build
** The target platform is needed because even if you run a compatability layer like Rosetta 2, some libraries such as kafka-python are not designed for inter-communication between different architectures
If you wish to deploy the services independently:
customer-bff-service
- https://github.com/Tavh/customer-platform/blob/main/customer-bff-service/README.md
customer-management-service
- https://github.com/Tavh/customer-platform/blob/main/customer-management-service/README.md
There should already be prepared data in the database because of the seeder in 'customer-management-service'
Fetching a customer's purchases:
curl -X GET http://localhost:5000/customers/1/purchases
Making a purchase
curl -X POST http://localhost:5000/customers/1/purchase/1
By inspecting the logs in customer-management-service, we can see that the message was succesfully consumed and a purhcase record was inserted to the database:
docker-compose logs customer-management-service
Airflow is deployed with a different docker-compose, for instructions, go to: https://github.com/Tavh/customer-platform/blob/main/airflow/README.md
Grafana is deployed with the main docker-compose, but the datasource and dashboard are configured separately, reffer to:
https://github.com/Tavh/customer-platform/blob/main/grafana/README.md
The frontend is a simple react app, for guidance go to: https://github.com/Tavh/customer-platform/blob/main/customer-frontend/README.md