## Microservices

- as a collection of small independent and loosely coupled services
- each service focus on a single feature
  -can be developed and deployed independely
  -faster dveelopment
  -better fault isolation
  -can use different programing language for each service
  -new feature can be added easily without affecting whole application

## communicate

http requests (api gateway)
meassage broker eg.(rabbitmq ,kafka)

## part 2

rabbitmq it is software used to communicate two microserverces.
es mai hum data ko queue mai daal dete hai aur consumer data ko consume karta hai
understand the message queue
use message queue to communicate b/w microservices
demo tutorial with nodejs and rabbit mq as message queue used a message broker

## order service

like this is order service(producer-service data ko store kar rha queue mai )
queue - data insert in queue { userId ,productName,orderId ,price}
message will remain in queue until any other service used this data.

## email service

(consumer -will received the data from queue and use it )
consumer will wait for the response jo service use karna chahata ho

## run rabbitMq with docker

docker run -p 5672:5672 rabbbitmq
//default port

## kafka implemenation

Apache Kafka is an open-source distributed event streaming platform used by thousands of companies for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications.

Certainly! Let me explain producers and consumers in the context of Kafka:

Producers:

1. Role: Producers are applications that publish (write) data to Kafka.
2. Function: They create new messages and send them to Kafka topics.
3. Behavior:
   - Can choose which topic partition to send a message to
   - Can send messages in batches for efficiency
   - Don't wait for acknowledgments from consumers
4. Use cases: Logging events, tracking user activities, collecting metrics, etc.

Consumers:

1. Role: Consumers are applications that subscribe to (read) data from Kafka topics.
2. Function: They read messages from topics and process them.
3. Behavior:
   - Can subscribe to one or more topics
   - Keep track of which messages they've read using offsets
   - Can be part of a consumer group for load balancing
4. Use cases: Analyzing data, triggering alerts, updating databases, etc.

Key points:

- Decoupling: Producers and consumers operate independently. Producers don't know who's reading their data, and consumers don't know who produced it.
- Scalability: You can have multiple producers writing to the same topic and multiple consumers reading from it.
- Fault tolerance: If a consumer fails, others in its group can take over its partitions.
- Persistence: Kafka stores messages on disk, allowing consumers to read past messages and catch up if they fall behind.

In essence, producers create and send messages, while consumers read and process these messages. This separation allows for flexible, scalable, and fault-tolerant data pipelines.