You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The architecture shows that there is one public API (API gateway). This is accessible for the clients.
28
+
The architecture shows that there is one public API (API gateway). This is accessible for the clients. This is done via HTTP request/response.
29
29
30
-
Each microservice hosts its own REST API that is only accessible via its Public API. Each microservice are within its own domain and have directly access to its own dependencies such as databases, stores, etc. This also means that a microservice can have zero, one or multiple databases (mssql, postgres, mongo, etc.). All these dependencies are not accessible for other microservices. In fact microservices are decoupled from each other.
31
-
Microservices are event based which means they can publish and/or subscribe to any events. By doing so one or more microservices can publish an event which can be received by one or more microservices unknown for the publisher.
30
+
The API gateway then routes the HTTP request to the correct microservice.
31
+
The HTTP request is received by the microservice that hosts its own REST API. Each microservice is running within its own domain and has directly access to its own dependencies such as databases, stores, etc. All these dependencies are only accessible for the microservice and not to the outside world. In fact microservices are decoupled from each other. This also means that the microservice does not rely on other parts in the system and can run independently of other services.
32
32
33
-
Events are used when something did happen (eg. when a user was created the event could be called UserCreated).
33
+
Microservices are event based which means they can publish and/or subscribe to any events occurring in the setup. By using this approach for communicating between services, each microservice does not need to know about the other services or handle errors occurred in other microservices.
34
34
35
-
RabbitMQ is used for publish/subscribe in order to deliver a message to multiple consumers.
36
-
Outbox has also been added to make sure we save the messages before they are published via RabbitMQ (in case RabbitMQ is not running or it can't be reached). Outbox is set up to MongoDB.
37
-
Messages can either be deleted afterwards or kept in MongoDB.
35
+
Event sourcing can be used to store events that have been published from the service performantly. By using the event sourcing approach the database will become the read model of the service. The only write operations done in the read model are when subscribed events need to update or insert data to the database.
38
36
39
-
Event sourcing is also possible. This will divide each microservice into having a write and read model.
37
+
Outbox can be used as a landing zone for events before they are published to the message broker. Events in the Outbox database are published to the message broker via a background service. If the connection to the message broker is broken, the background service will try until the event has been published successfully. After the event has been published successfully to the message broker, the event in the Outbox database is either removed or kept with a flag that it has been published successfully.
38
+
39
+
The Outbox database and the event store have essentially the same data format. The major difference is that the event sourcing is meant to be a permanent and immutable store of domain events, while the Outbox database is meant to be highly ephemeral and only be a landing zone for domain events to be captured inside change events and forwarded to downstream consumers.
40
+
41
+
All of this is optional in the application and it is possible to only use parts that the service needs. Eg. if the service does not want event sourcing via an event store but rather have a read/write database (like in the user service).
40
42
41
43
## Structure
42
44
-**Api**: Api gateway.
@@ -46,7 +48,7 @@ Event sourcing is also possible. This will divide each microservice into having
46
48
-**Infrastructure**: Infrastructure for microservices (eg. setup RabbitMQ, Consul, Logging, etc.)
47
49
48
50
### Infrastructure
49
-
Infrastructure contains the logic for the different services and keeps most of the boiler code away from our services.
51
+
Infrastructure contains the logic for the different services and keeps most of the boiler code hidden from the services.
50
52
51
53
#### Consul
52
54
Consul is used as service discovery. This is used by the services and the API gateway in order to call other services by name/id, rather than by uri.
@@ -127,9 +129,10 @@ Swagger is used for API documentation.
127
129
128
130
### Api
129
131
Api gateway is using Ocelot to have a unified point of entry to all microservices.
132
+
Configuration for this can be found in `ocelot.json`.
130
133
131
134
### Microservice
132
-
Microservices are just REST APIs and are created without any knowledge to each other. If a microservice wants to notify another service it simply publishes an event and the services subscribing to this event can take action on it using publish/subscribe with RabbitMQ.
135
+
Microservices are REST APIs and are created without any knowledge to each other. If a microservice wants to notify other services it simply publishes an event and the services subscribing to this event can take action on it using publish/subscribe with RabbitMQ.
133
136
134
137
A microservice consists of:
135
138
-**Controllers**: API endpoints for the microservice.
@@ -138,5 +141,5 @@ A microservice consists of:
138
141
-**EventHandlers**: Handlers for events to take action when events are being published.
139
142
-**Repository**: Repository used when writing to the application. This will also publish the correct events.
140
143
141
-
Next to the microservice is the data model. This contain the migrations, models and update handlers (if used) for the database.
144
+
Next to the microservice is the data model. This contain the migrations, models and update handlers (if using event sourcing) for the database.
0 commit comments