Tuesday, 5 November 2024

Event Driven Microservice Architecture using Kafka

 

Electronic Health Record (EHR) Microservice is a robust, modern system developed using the Spring Boot framework.

It is designed with a microservices architecture pattern and employs Event-Driven Architecture (EDA) with Kafka as the message broker. EDA allows the system to respond in real time, enabling asynchronous communication between microservices through Kafka, which provides high-throughput and low-latency message delivery. 

  1. Microservice Architecture Patterns
  • API Gateway Pattern: Implemented using Spring Cloud Gateway, it acts as a single entry point for clients, routing requests to appropriate microservices and aggregating the responses. This reduces the number of round trips between the client and application.
  • Database per Service: Each microservice has its own dedicated database, either SQL or noSQL. This ensures loose coupling, improves performance, and enables each service to use a type of database that is most suited to its needs.
  • Event Sourcing Pattern: This pattern ensures all changes to application state are stored as a sequence of events. Not just can we query these events, we can also use the event log to reconstruct past states, and as a foundation to automatically adjust the state to cope with retroactive changes.
  • Command Query Responsibility Segregation (CQRS): This pattern separates read and update operations for a data store, optimizing performance, scalability, and security.
  • Distributed Tracing: Implemented using Sleuth and Zipkin, it provides visibility into the system by tracing requests across multiple services. This is crucial for debugging and latency optimization.
  • External Configuration: Using Spring Cloud Config Server and library, configuration across multiple services can be managed centrally. This is particularly useful in a microservices environment where there are many services to manage.
  • Service Discovery Pattern: Implemented using Netflix Eureka server and client, it allows microservices to find and communicate with each other without hard-coding hostname and port. This is crucial in dynamic environments where the number of instances of a service can autoscale.
  • Circuit Breaker Pattern: Implemented using Resilience4j, it prevents a network or a service failure from cascading to other services. It does so by stopping the system from making a failing service call, returning a default response instead. 
  1. Caching: Using Ehcache, it significantly improves the performance of the system by storing the data in memory that the application frequently accesses. 
  1. Security: Implemented using Spring Security with Role-Based Access Control (RBAC), it ensures data access control at granular level, making the system more secure. 
  1. Customize Auditing Service Microservice: This feature provides crucial information about the activities in the system, it helps in debugging and provides an audit trail which is a requirement for many compliance standards. 
  1. Translation using FHIR (Fast Healthcare Interoperability Resources): FHIR is a standard for health care data exchange, published by HL7, which makes integration of EHR data smoother and more robust. 
  1. Unit Test Coverage: Implemented using JUnit 5, it ensures that the codebase works as expected and helps to prevent regressions when changes are made. 
  1. Behavior-Driven Development (BDD): Implemented using Cucumber, it encourages collaboration between developers, QA and non-technical or business participants in a software project. 
  1. Error and Exception Handling: Custom classes are used to handle errors and exceptions, ensuring a consistent strategy for handling errors and exceptions across the application. 
  1. Continuous Integration and Continuous Deployment: Using Jenkins 
  1.  Containerization: using docker
















 

This meticulously designed and implemented architecture allows the EHR Microservice to be highly scalable, maintainable, efficient, and secure, making it well-suited to the complex and sensitive nature of health record management.

 

Below is the list of the microservice

 1.        Netflix Eureka Discovery Microservice:

https://github.com/manaspratimdas/starter-eda-microservice/tree/eureka-server 

2.        Spring Cloud API Gateway

 https://github.com/manaspratimdas/api-gateway/tree/master 

3.        Spring Configuration Server

https://github.com/manaspratimdas/configserver-app 

4.        Configuration Library

https://github.com/manaspratimdas/configserver 

5.        Shared Library

https://github.com/manaspratimdas/share 

6.        Audit Service

https://github.com/manaspratimdas/audit-service-ms 

7.        PatientRecordMS

https://github.com/manaspratimdas/patient-record-ms 

8.        InteroperabilityMS

https://github.com/manaspratimdas/interoperability-ms

 

 

 

 

 

 

 

 

 

 



Streaming with Kafka API

The Kafka Streams API is a Java library for building real-time applications and microservices that efficiently process and analyze large-sca...