SOLID Software Design Principles and How Fit in A Microservices Architecture Design
SOLID Software Design Principles and How Fit in A Microservices Architecture Design
HomeBrowse
Search
PathsChannelsBookmarks
:)
Kobi Hikri
Microservices
SOLID
Architecture Design
Introduction
SOLID Software Design Principles - Brief History
The Single Responsibility Principle
The Open/Closed Principle
The Liskov Substitution Principle
The Interface Segregation Principle
The Dependency Inversion Principle
Microservices Design Principles - Todays Hype
Why and How It All Fits Together
A “One by one” Approach - Each service on its own
A “Holistic” Approach - A system of (micro)services
A “Bridged” Approach
In Conclusion
Top
Introduction
Design principles are good; they can guide us when making
important decisions. Relying on proven and mature “advice”,
when designing our software, is helpful - in particular, when
considering the following facts:
The domain of computer-science is rather “new” to our
world.
As such, new technologies, development languages,
runtimes, and paradigms are rather common.
Thus, the “book” of computer-science is not yet (and
may never be) complete. Chapters are being added to it
constantly, as real-world requirements arise and the
software industry evolves to meet them.
Relying on “best practices” when observing a newly
discovered territory will prove beneficial (at least
statistically).
Many markets are very competitive. Bringing your
product to shelf can have both a tight budget and time
constraints.
Under such circumstances, it is desirable to have as
few “open” questions as possible.
Some questions have been asked plenty of times and
we can rely on proven answers to them.
Writing great software is difficult. There are many
simple things you can do that are, simply, not correct.
Acknowledging this fact is actually a driving-force
towards the development of better ways of doing
things.
Unlike the previous bullet, here we are not talking about
answers to known questions, but rather about the
manner in which we approach answering our remaining
open questions.
This article is about the “SOLID” software design principles
in general and how they fit the sub-domain of microservices,
in particular.
I hope you enjoy this read. Let’s get started!
Single Responsibility
Open/Closed
Liskov Substitution
Interface Segregation
Dependency Inversion
The Car class has three acceleration methods - one for each
car model.
If we were to introduce an additional car model to our
system, we would have to modify the Car class itself!
That means that when extending our system we performed
an undesired modification.
Let’s look at a design which does not violate the
Open/Closed principle:
class Car
{
Engine engine;
}
See the “problem” there?
Our high-level class, Car , is tightly coupled to
the Engine class. The Engine class, in-turn, is tightly coupled
with the Gear class.
We’ve created a tightly coupled system. Every lower-level
component is being used directly by the level above it.
How can we solve this situation? Well, rather simply, using
interfaces between components.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
internal interface IGear
{
}
class Car
{
IEngine engine;
}
By extracting the “contract” between each of the dependent
entities, we’ve decoupled each entity from its former
dependencies. A contract is now being shared between each
entity and its dependency.
Independent Deployment
Modularity
Communication
Size
A “Bridged” Approach
Life, as life goes, will present difficulties. No single approach
you take, will guard you from tough choices.
Choosing the “by the book” approach, with each
microservice managed in its own repository, having its own
build and versioning process will certainly have benefits. But
it will also have an overhead (e.g. repository management).
Then again, choosing the “holistic” approach, where all
services are managed and built from the same codebase will
have less overhead in some aspects (e.g. build time, code
duplication). It will also present “problems” when
considering others (e.g. service versioning).
Can we think of a “nice place in the middle” where the two
approaches can converge?
I think that in most cases, we can.
For example, how about presenting an abstraction of a
“microservice group”?
Now, a group of microservices might be defined by the
technologies and dependencies shared by the services.
Or by the logical aspects they are managing.
The “grouping” of microservices should not be strict but
rather agile. This means that if we’ve come to understand
that grouping services according to specific parameters
doesn’t work well for us, we can always change our grouping
definition.
Using this approach, we could look “holistically” at a group
of microservices and still have control over this group’s
versioning, build process, dependencies, and codebase
management.
In Conclusion
In this short journey, I’ve tried to do three things (yeah, I
know, it violates the single responsibility principle).
The first thing was to explain the SOLID software design
principles. In particular, I’ve tried to present them in a
favorable manner. Why? Because they have proven
beneficial time after time.
Then, I’ve presented the new kid on the block: the concept
of a microservice.
I began by explaining that the terms are not comparable, but
rather (optionally) composable. You can combine the two
ideas into your system design.
Mostly, I’ve tried to emphasize the fact that working with
microservices is interesting but can present an overhead in
some aspects. Particularly when implemented in a “strict
academical” manner.
Next, I’ve taken the “other side” and presented the other
extreme point of view.
To conclude this article, I’ve presented with an idea of how
to bridge the two points of view.
Fortunately, I’ve been around long enough to experience
both “extreme” implementations and have come to
understand that, for practical reasons, agility and an open
mind is the key to success.
Therefore, whether or not you take my proposed idea for
bridging the two points of view, or decide to go in a
completely different way, I wish you success and remind you
to always check where your overhead is - then, optimize.
Thank you very much for sticking with me.
Feel free to drop me a word in the comments section.
Thank you, Kobi
63
Features
·
Authors
·
Mobile & offline apps
·
Blog
·
Help center
·
How-to videos
·
Terms of use
·
Privacy policy
Send feedback
Get support