{"id":21939018,"url":"https://github.com/jeffreyquan/nest-microservices","last_synced_at":"2026-04-13T23:04:34.923Z","repository":{"id":115054501,"uuid":"414173080","full_name":"jeffreyquan/nest-microservices","owner":"jeffreyquan","description":"Example application of microservices in Nest + Kafka","archived":false,"fork":false,"pushed_at":"2021-10-08T16:14:26.000Z","size":396,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-27T14:48:37.023Z","etag":null,"topics":["kafka","nestjs","postgresql","typeorm","typescript"],"latest_commit_sha":null,"homepage":"https://nestjs.com/","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/jeffreyquan.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":"2021-10-06T10:50:48.000Z","updated_at":"2024-08-11T12:34:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"6cc1fbe4-f92f-40c4-b744-d0458171417d","html_url":"https://github.com/jeffreyquan/nest-microservices","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffreyquan%2Fnest-microservices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffreyquan%2Fnest-microservices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffreyquan%2Fnest-microservices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffreyquan%2Fnest-microservices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffreyquan","download_url":"https://codeload.github.com/jeffreyquan/nest-microservices/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244973695,"owners_count":20541022,"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","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":["kafka","nestjs","postgresql","typeorm","typescript"],"created_at":"2024-11-29T02:16:27.030Z","updated_at":"2026-04-13T23:04:34.890Z","avatar_url":"https://github.com/jeffreyquan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Nest Microservices\n\nThis is a simple example of microservices in [Nest](https://nestjs.com/) with Kafka. Both are designed as [Hybrid applications](https://docs.nestjs.com/faq/hybrid-application) i.e. listen to HTTP requests and make use of connected microservices.\n\nWe have two services:\n\n- User Service\n- Registration Service\n\nThe example demonstrates the following flow:\n\n1. User is created in the User Service with a name and age.\n\nThis can be done via Postman with a POST request to `http://localhost:3000/api/users` and a JSON body including name and age.\n\n```js\n{\n    \"name\": \"Goku\",\n    \"age\": 88\n}\n```\n\n2. The event `user.registration.pending` is emitted with the user data.\n3. Registration Service listens to the `user.registration.pending` event and handles the user data.\n4. User's age is assessed. If the user is 18 or over, the registration status is `approved`. Otherwise, the status is `rejected`. Note: the age chosen and this assessment is arbitrary\n5. A registration is created and the registration ID and status is emitted with the event `user.registration.fulfilled`.\n6. The User Service listens to the `user.registration.fulfilled` event and updates the user's registration status in the database.\n\n## Installation\n\n```bash\n\n# user-service folder and registration-service folder\n\nnpm install\n\n```\n\n## Environmental Variables\n\n```bash\n# Create .env files using the .env.example files as a template\n\n# Make sure the POSTGRES_USER, POSTGRES_PASSWORD AND POSTGRES_DB is the same across all three .env files\n# If you are running Postgres locally, comment out the postgres-db service in the docker-compose.yml file\n\n# root\nPOSTGRES_USER=\nPOSTGRES_PASSWORD=\nPOSTGRES_DB=\n\n# user-service folder\nPOSTGRES_USER=\nPOSTGRES_PASSWORD=\nPOSTGRES_DB=\nPOSTGRES_PORT=5432\nPOSTGRES_HOST=localhost\n\n# registration-service folder\nPOSTGRES_USER=\nPOSTGRES_PASSWORD=\nPOSTGRES_DB=\nPOSTGRES_PORT=5432\nPOSTGRES_HOST=localhost\n\n```\n\n## Running the app\n\n```bash\n\n# To run Postgres, Kafka and Zooper\n\n# root\n\ndocker-compose up\n\n# user-service\n\nnpm run start:dev\n\n# registration-service\n\nnpm run start:dev\n\n```\n\n## Stopping docker containers\n\n```bash\n\ndocker-compose down\n\n```\n\n## Known Issues\n\nSometimes when starting the docker containers, the Kafka and Zookeeper services terminate referencing the error: `Error:KeeperErrorCode = NodeExists`. This prevents the user and registration services from connecting to Kafka. I would appreciate any help to fix this.\n\nAlternatively, you can run Kafka and Zookeeper locally following the instructions from the [Kafka Quickstart Guide](https://kafka.apache.org/quickstart).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffreyquan%2Fnest-microservices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffreyquan%2Fnest-microservices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffreyquan%2Fnest-microservices/lists"}