{"id":23151226,"url":"https://github.com/gispada/nestjs-python-kafka-microservices","last_synced_at":"2025-08-17T20:31:48.660Z","repository":{"id":118850425,"uuid":"513646248","full_name":"gispada/nestjs-python-kafka-microservices","owner":"gispada","description":"Project to experiment with a microservices architecture based on Apache Kafka","archived":false,"fork":false,"pushed_at":"2023-07-08T10:11:29.000Z","size":317,"stargazers_count":21,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T12:24:25.375Z","etag":null,"topics":["apache-kafka","microservices","nestjs","python","schema-registry"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gispada.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-13T19:27:20.000Z","updated_at":"2025-02-25T23:11:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b2b6471-ebae-437e-bfa9-70ee367c0127","html_url":"https://github.com/gispada/nestjs-python-kafka-microservices","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gispada/nestjs-python-kafka-microservices","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gispada%2Fnestjs-python-kafka-microservices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gispada%2Fnestjs-python-kafka-microservices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gispada%2Fnestjs-python-kafka-microservices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gispada%2Fnestjs-python-kafka-microservices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gispada","download_url":"https://codeload.github.com/gispada/nestjs-python-kafka-microservices/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gispada%2Fnestjs-python-kafka-microservices/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270902112,"owners_count":24665207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apache-kafka","microservices","nestjs","python","schema-registry"],"created_at":"2024-12-17T18:31:14.540Z","updated_at":"2025-08-17T20:31:48.638Z","avatar_url":"https://github.com/gispada.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Microservices architecture with NestJS, Python and Kafka\n\nThe goal of this project is to practice a microservices architecture based on **Apache Kafka** with services written in different languages — **TypeScript** and **Python** — that communicate between them. The Kafka layer is configured to have a basic level of redundancy, with each component running on three instances.\n\nIn total, the system is composed of 17 containers:\n- 3x **Apache Kafka** brokers\n- 3x **ZooKeeper** instances to orchestrate the Kafka infrastructure\n- 3x **Schema Registry** instances\n- 1x **NGINX** load balancer for Schema Registry\n- 1x **Apache Kafka UI**, a web-app to better interact with Kafka (exposed on http://localhost:8080, credentials `admin:password`)\n- 1x **NestJS** instance for the `vehicles-stock` service (exposed on http://localhost:3002)\n- 1x **PostgreSQL** database for the previous service\n- 2x **Python** instances for the `price-estimate` service\n- 1x **NestJS** instance for the `vehicles-ads` service (exposed on http://localhost:3003)\n- 1x **MongoDB** database for the previous service\n\n![Infrastructure diagram](diagram.png)\n\n## Services\n\n### vehicles-stock\nThis service exposes an HTTP REST API that allows users to create and list vehicles, and is also a **Kafka producer**.\n\nA POST request to `http://localhost:3002/stock` with the following body\n```json\n{\n  \"vin\": \"vin\",\n  \"model\": \"model\",\n  \"manufacturer\": \"manufacturer\",\n  \"year\": 2022,\n  \"odometer\": 1000,\n  \"odometerUnit\": \"odometerUnit\"\n}\n```\ncreates a new vehicle in the local Postgres database and emits data to the `stock.vehicle-created` topic in Kafka.\n\nA GET request to `http://localhost:3002/stock` retrieves vehicles.\n\n### price-estimate\nThis service consumes `stock.vehicle-created` to calculate a price for vehicles. The calculation simply generates a random number after 30 seconds to simulate some form of processing.\n\nWhen done, it emits the vehicle with its price to the `stock.vehicle-processed` topic in Kafka. This service is **both a consumer and a producer**.\n\n### vehicles-ads\nThis service only exposes an HTTP endpoint to get a list of ads — `http://localhost:3003/ads` — and is a **Kafka consumer**: it consumes `stock.vehicle-processed` to create vehicle ads in the local MongoDB database.\n\n## Schema registry\n\nMessages are encoded and decoded using **JSON schemas** registered on the schema registry, to enforce structure: each topic requires messages to conform to a specific schema, and trying to emit one that does not will result in an error.\n\nCurrently each service registers its own schema, so common schemas may be duplicated across services — this can be improved.\n\n## Startup\n\nRun `docker compose up -d` to create the infrastructure and start the containers; the process may take some time. A few services need to wait for the schema registry servers to be up, so they use a *wait-for* script with a timeout of 90 seconds.\n\nThe following services will then be exposed to the host machine:\n\n- Kafka Web UI on `http://localhost:8080` (use `admin:password` to access it)\n- Vehicles stock service on `http://localhost:3002`\n- Vehicles ads service on `http://localhost:3003`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgispada%2Fnestjs-python-kafka-microservices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgispada%2Fnestjs-python-kafka-microservices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgispada%2Fnestjs-python-kafka-microservices/lists"}