Microservices

Maya Alexandera
2 min readJan 4, 2021
A giant monolith found in Utah, very shortly after my departure this past November.

Monolithic Model

So far all the applications I’ve made have followed a monolithic structure — where all my code is located in and deployed from one single codebase. I imagine this is the first structure to which most developers are introduced.

Monolith contains all of the following to run ALL features of an application:

  • Routing
  • Middlewares
  • Business Logic
  • Database Access

A single Microservice contains all of the following to implement ONE feature of an application:

  • Routing
  • Middlewares
  • Business Logic
  • Database Access

Microservices allow developers to create a modular-based application that is easier to deploy and maintain.

The biggest challenge in designing microservices revolves around data management. A cardinal rule for database access is that services will never reach into another service’s database. This rule ensures that each service runs independently — which will be especially advantageous in the event one service’s schema/structure changes. A bonus to adherence to this guideline is that the developer can choose the most appropriate database model for optimum efficiency.

Communication Strategies Between Services

What happens if we want to create a feature that requires data from two different databases?

Sync/Async

(Not like Javascript!)

Synchronous Communication

A synchronous communication style in the microservices world dictates that services communicate with one another using direct requests (these are requests made to the services themselves, NOT the services’ database).

Asynchronous Communication

When using an asynchronous approach there are a couple of structural differences. Each service will still maintain its own database, but now every time an entry is created an event will be passed to a component, ‘Event Bus’. This concept reminds me of Redux in the sense that there is a centralized hub through which all request traffic passes. This event bus will intake all database entries as ‘events,’ and notify the services that will require this data for their own purposes. While this does require more storage space, it allows every service to be completely autonomous — making for a truly modular application.

--

--