Mesoservice pattern or ‘pluralitas non est ponenda sine neccesitate’

The philosophical viewpoint

The optimization viewpoint

The fallacies of distributed computing viewpoint

Mesoservice pattern

  • No “embedded” elements in the REST APIs and collections are always paginated
  • It does not use Hypermedia APIs
  • Contract-first approach using Swagger for REST/Message microservices
  • Contract-first approach using Swagger for REST/Message mesoservices (the Swagger of a mesoservice is the composition of the Swagger of its microservices)
  • Contract-first approach using GraphQL schema for the GraphQL service (also defined by a Swagger), describing the business functionality of the application
  • API Schema checking and code generation based on the contracts (Swagger and GraphQL schema)
  • API Gateway friendly since all APIs have a Swagger to be exposed through an API Gateway
  • Authentication (client application and user) provided by the API Gateway through OAuth2 (authorization code — former implicit method — and password method)
  • Coarse-grained authorization provided by the API Gateway
  • Fine-grained authorization provided by the mesoservices based on a JWT generated by the API Gateway and propagated between services.
  • An API Gateway that provides functionality for APIs based on websockets is preferred (e.g., WSO2 API Manager) since they enable push to the clients using this kind of technology (MQTT over websocket was used with success)
  • Queries that need to retrieve data owned by multiple mesoservices are easily implemented in the GraphQL service
  • A given mutation is prescribed to be owned by sole one given mesoservice (reducing the need for the application of the saga pattern)
  • Mesoservices applies the database per service pattern for a given set of “tables” that make business sense
  • It is commonly based on ORM technologies (e.g., JPA) but not restricted
  • It is common to use a shared library with common domains tables, e.g., countries, states, etc…
  • In a classical relational data store, a lock in the main entity (SELECT … FOR UPDATE NOWAIT) is recommended for all mutations. This technique avoids expensive lock waits, consequently, it increases the scalability of the overall solution
  • Each mesoservice is defined as a container application (usually a Docker container running a OpenJDK JVM over Alpine operating system configured through confd)
  • Java services based on SpringBoot have a huge minimal memory footprint (1GB, [11,12]), therefore, mesoservices pattern contributes to reduce the overall infrastructure needed since the pattern reduces the number of services
  • Intercommunication between GraphQL service and Mesoservices are REST/HTTP based for queries (using a circuit breaker, usually Hystrix) and REST/message-based for mutations
  • Intercommunication between microservices in a given mesoservice are based on memory calls
  • Intercommunication between mesoservices can be REST/message based and REST/HTTP based (using a circuit breaker, usually Hystrix). The former is the preferred
  • REST/message based applies a publish/subscribe message exchange pattern. It uses REST over JMS 1.0 subscription plus database lock synchronization, Apache Kafka groupid or JMS 2.0 shared subscription (createSharedConsumer/createSharedDurableConsumer) in order to guarantee that only one consumer process a given message.
  • Functional Alignment
  • Easier Integration
  • Lower Development and Maintenance costs
  • Reduced infrastructure needs
  • It is hard to define the granularity of the mesoservices (it requires business knowledge)
  • Contract-first put emphasis on the definition of the contracts

Conclusion

References

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Echo Ridge Lot 32 — Framing Started

Echo Ridge Lot 32 – Framing Started

AWS Solution Architect Professional — Exam tips -2021

Convert MOV to GIF in Java

Python Numbers: Python Complete Course — Part 11

A dummy image for better reading and navigation.

#freestockphoto (Friday 27th 08PM)

The HoloBuilder Add-In for Autodesk Navisworks

Add a dockerized wordpress to your web application

A new home for Project Delta

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alessandro Gerlinger Romero

Alessandro Gerlinger Romero

More from Medium

Communication Best Practices — Giving and Receiving Feedback

When Should You Apply CQRS Software Architecture Pattern?

Domain Driven Design— Solving the problems for solutions

Async Processing API