Microservices Starter Kit v1.0

(Updated Dec 18, 2024)

 


 

Microservice Design Principles



Separation of Concerns

This principle asserts that software should be separated based on the kinds of work it performs. For instance, consider an application that includes logic for identifying noteworthy items to display to the user, and which formats such items in a particular way to make them more noticeable


Single Responsibility Principle

The single responsibility principle applies to object-oriented design, but can also be considered as an architectural principle similar to separation of concerns. It states that objects should have only one responsibility and that they should have only one reason to change. Specifically, the only situation in which the object should change is if the manner in which it performs its one responsibility must be updated. Following this principle helps to produce more loosely coupled and modular systems, since many kinds of new behavior can be implemented as new classes, rather than by adding additional responsibility to existing classes. Adding new classes is always safer than changing existing classes, since no code yet depends on the new classes.


Loose Coupling

Coupling refers to the degree of direct knowledge that one service has of another. Loose coupling in computing is interpreted as encapsulation vs. non-encapsulation. No single service should have intimate knowledge of the inner workings of another service. Further, each service should define its contract based on a generic interface that does not expose any of the inner workings of the service.


Auto-Scaling

Services should be automatically scalable to meet the demand real-time. At peak times service should scale up to ensure consistency of response time and during down time the service should scale down to reduce cost.


Encapsulation

Different parts of an application should use encapsulation to insulate them from other parts of the application. Application components and layers should be able to adjust their internal implementation without breaking their collaborators as long as external contracts are not violated. Proper use of encapsulation helps achieve loose coupling and modularity in application designs, since objects and packages can be replaced with alternative implementations so long as the same interface is maintained.


Bounded Contexts

Bounded contexts are a central pattern in Domain-Driven Design. They provide a way of tackling complexity in large applications or organizations by breaking it up into separate conceptual modules. Each conceptual module then represents a context that is separated from other contexts (hence, bounded), and can evolve independently. Each bounded context should ideally be free to choose its own names for concepts within it, and should have exclusive access to its own persistence store.