---
# System prepended metadata

title: MicroService
tags: [learning, nodejs]

---

# MicroService

###### tags: `learning` `nodejs`

## What Is Monolithic Server
Contains all the routing, middleware , business , logic, db  access to implement all features of our application in one place.

## What is Microservice
A single Microservice contains all the routing, middleware , business , logic, db  access to implement just one feature or part of our Application.
eg Service A, Service B , Service C all have their own ** routing, middleware , business , logic, db  access.**

One Of The Bigest Challenge Of MicroService Is 
**Data Management Between Service**

In MicroService
- Each Service get its own Database (If it need one)
- Service will never , ever reach into another services database.

#### Why Database Per Service
- We want each service to run independently of other services 
- Database schema/structure might change unexpectedly
- Some services might function more efficiently with different types of DB's (sql vs nosql)


#### Communication Strategies Between Services
- Sync:- Services Communicates with each other using direct requests

* 


- - Async: Communicate using events
* Here we Use an **Event Bus** all requests are made to and emitted from the **Event Bus**.
    But It is rarely used
    
* Second way to use Asyn

1. Define your request very clear and detailed, Then create a db for Sevice D that requires the query data from other services.

1. Next we use an **Event Bus** to listen to request made to other services, then send the log data to Service D database for saving when needed. It notifiy us when an event happens in other services

Pro Of This Technique
- Service D has Zero dependencies on other services
- service D will be extremely fast
Con
- Data Duplication, Paying for extra storage + etra DB
- Harder to Understand.











## Section 2
### Creatind A Post Project

- First What Services should We create? (Post, Comment)
- Next Picture the Goal and Responsibilities of the Services











- We are only using the query service to read data - so when we need to create either comments or post we go to their individual services. 




