{"id":21712311,"url":"https://github.com/ashutoshsahoo/distributed-transactions-kafka","last_synced_at":"2025-04-12T18:08:18.897Z","repository":{"id":131092184,"uuid":"510014796","full_name":"ashutoshsahoo/distributed-transactions-kafka","owner":"ashutoshsahoo","description":"Distributed Transactions in Microservices with Kafka Streams and Spring Boot","archived":false,"fork":false,"pushed_at":"2023-12-08T19:28:20.000Z","size":234,"stargazers_count":8,"open_issues_count":0,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T18:04:37.989Z","etag":null,"topics":["avro-format","avro-kafka","avro-schema","avro-schema-registry","ditributed-tracing","ditributed-transactions","kafka","kafka-registry","kafka-streams","kafka-ui","microservices","spring-boot","spring-boot-kafka","spring-boot-kafka-streams","spring-sleuth"],"latest_commit_sha":null,"homepage":"","language":"Java","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/ashutoshsahoo.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,"zenodo":null}},"created_at":"2022-07-03T12:18:54.000Z","updated_at":"2024-10-06T01:45:54.000Z","dependencies_parsed_at":"2023-12-08T20:39:26.477Z","dependency_job_id":null,"html_url":"https://github.com/ashutoshsahoo/distributed-transactions-kafka","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/ashutoshsahoo%2Fdistributed-transactions-kafka","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashutoshsahoo%2Fdistributed-transactions-kafka/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashutoshsahoo%2Fdistributed-transactions-kafka/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashutoshsahoo%2Fdistributed-transactions-kafka/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashutoshsahoo","download_url":"https://codeload.github.com/ashutoshsahoo/distributed-transactions-kafka/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248610346,"owners_count":21132921,"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":["avro-format","avro-kafka","avro-schema","avro-schema-registry","ditributed-tracing","ditributed-transactions","kafka","kafka-registry","kafka-streams","kafka-ui","microservices","spring-boot","spring-boot-kafka","spring-boot-kafka-streams","spring-sleuth"],"created_at":"2024-11-25T23:37:53.037Z","updated_at":"2025-04-12T18:08:18.872Z","avatar_url":"https://github.com/ashutoshsahoo.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Distributed Transactions in Microservices with Kafka Streams and Spring Boot\n\n\n\n## Description\nThere are three microservices: \\\n`order-service` - it sends `Order` events to the Kafka topic and orchestrates the process of a distributed transaction \\\n`payment-service` - it performs local transaction on the customer account basing on the `Order` price \\\n`stock-service` - it performs local transaction on the store basing on number of products in the `Order`\n\nHere's the diagram with our architecture:\n\n![image](arch.png)\n\n(1) `order-service` send a new `Order` -\u003e `status == NEW` \\\n(2) `payment-service` and `stock-service` receive `Order` and handle it by performing a local transaction on the data \\\n(3) `payment-service` and `stock-service` send a reponse `Order` -\u003e `status == ACCEPT` or `status == REJECT` \\\n(4) `order-service` process incoming stream of orders from `payment-service` and `stock-service`, join them by `Order` id and sends Order with a new status -\u003e `status == CONFIRMATION` or `status == ROLLBACK` or `status == REJECTED` \\\n(5) `payment-service` and `stock-service` receive `Order` with a final status and \"commit\" or \"rollback\" a local transaction make before\n\n\n## Run application\n\n* Use docker to deploy kafka with registry.\n\nSet docker host ip\n\n```sh\nexport DOCKER_HOST_IP=127.0.0.1\n```\n\nor on windows powershell\n\n```powershell\n$env:DOCKER_HOST_IP = \"127.0.0.1\"\n```\n\n```shell\ndocker compose -f zk-single-kafka-multiple-schema-registry-ui.yml up -d\n```\n\nOpen UI for Apache Kafka at [Kafka Control Center ](http://localhost:9021/).\n\n* Run gradle build to generate avro source files\n\n```shell\ncd common-lib\ngradle clean build\n```\n\n* Run application\n    * order-service\n\n  ```shell\n  cd order-service\n  gradle clean bootRun\n  ```\n  Open [swagger-ui](http://localhost:8080/swagger-ui/index.html).\n    * payment-service\n\n  ```shell\n  cd payment-service\n  gradle clean bootRun\n  ```\n    * stock-service\n\n  ```shell\n  cd stock-service\n  gradle clean bootRun\n  ```\n\n* Use following request to generate orders\n\n```shell\ncurl --location --request POST 'http://localhost:8080/orders/generate'\n```\n\n* Use following request to check orders status\n\n```shell\ncurl --location --request GET 'http://localhost:8080/orders'\n```\n\n## Stop application\n\n* Use ctrl+c to cancel running applications\n* Use following command to stop and remove kafka containers\n\n```shell\ndocker compose -f zk-single-kafka-multiple-schema-registry-ui.yml down\n```\n\n## Kubernetes Deployment\n\n* Start kafka\n\n```shell\nhelm repo add confluentinc https://confluentinc.github.io/cp-helm-charts/\nhelm repo update\nhelm install my-kafka -f ./k8s/kafka/values.yaml confluentinc/cp-helm-charts\n```\n\n* Application Deployment\n\n```shell\ngradle clean dockerTag\nkubectl apply -f ./k8s/zipkin\nkubectl apply -f ./k8s/app\n```\n\n* Use following request to generate orders\n\n```shell\ncurl --location --request POST 'http://localhost:30001/orders/generate'\n```\n\n* Use following request to check orders status\n\n```shell\ncurl --location --request GET 'http://localhost:30001/orders'\n```\n\n* Clean up\n\n```shell\nkubectl delete -f ./k8s/app\nkubectl delete -f ./k8s/zipkin\nhelm delete my-kafka\n```\n\n* Expose Confluent Control Center via NodePort\n\n```shell\nkubectl patch svc my-kafka-cp-control-center --type='json' -p '[{\"op\":\"replace\",\"path\":\"/spec/type\",\"value\":\"NodePort\"}]'\n```\n\n## Reference\n\n* [Spring Boot Kafka](https://github.com/ashutoshsahoo/gs-spring-boot-kafka)\n* [Distributed Transactions in Microservices with Kafka Streams and Spring Boot](https://piotrminkowski.com/2022/01/24/distributed-transactions-in-microservices-with-kafka-streams-and-spring-boot/)\n* [Kafka Streams Data Types and Serialization](https://docs.confluent.io/platform/current/streams/developer-guide/datatypes.html)\n* [Confluent Platform Helm Charts](https://github.com/confluentinc/cp-helm-charts)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashutoshsahoo%2Fdistributed-transactions-kafka","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashutoshsahoo%2Fdistributed-transactions-kafka","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashutoshsahoo%2Fdistributed-transactions-kafka/lists"}