Microservice Architecture Pattern (1)
Microservice Architecture Pattern (1)
Architecture Pattern
COMP 301 .Software Architectures and Tools
Week 9
Microservice Pattern
Description
• The microservices architecture pattern is quickly gaining ground
in the industry as a viable alternative to monolithic applications
and service-oriented architectures.
• Because this architecture pattern is still evolving, there’s a lot of
confusion in the industry about what this pattern is all about and
how it is implemented.
• Regardless of the topology or implementation style you
chose(disccussed later on) , there are several common core
concepts that apply to the general architecture pattern.
Separately Deployed Units
• Each component of the microservices architecture is
deployed as a separate unit, allowing for easier deployment
through an effective and streamlined delivery pipeline, increased
scalability, and a high degree of application and component
decoupling within your application.
Notion of a Service Component
• Service components contain:
1. one or more modules (e.g., Java classes)
that represent either a single-purpose
function (e.g., providing the weather for a
specific city or town) or
2. an independent portion of a large business
application(e.g., stock trade placement or
determining auto-insurance rates).
Easy to Implement
• it’s synchronous communication! We’ve all done it
before. And thus we can do it again easily. Let’s just get
the latest version of our favorite HTTP client library and
implement it.
2. Simple Messaging
• Asynchronous messaging is the next option we take a look at.
Pipeline contains
Schema
• It’s worthy to note that messages (even if they are JSON) define a
certain schema within the message broker.
• The last scenario is similar to the messaging example, but we’re not
sending whole messages (i.e. big JSON objects) but instead only a
pointer to the payload.
• In this case, the message is more like an event. It signals that something
happened, for example that “the order with ID 4711 has been shipped”.
• Thus, the message itself only contains the type of the event
(“orderShipped”) and the ID of the order (4711).
• If Service 2 is interested in the “orderShipped” event, it can then
synchronously call Service 1 and ask for the order data.
When to use which Approach?
• There is no black-and-white decision between the communication
patterns described above.
• However, let’s try to find some indications on when we might use
which approach.
• We might want to use Synchronous Calls if:
• we want to query some data, because a query is not changing any state so we
don’t have to worry about distributed transactions and data consistency
across service boundaries
• the call is allowed to fail and we don’t need a sophisticated retry mechanism
When to use which Approach?
• We might want to use Simple Messaging if:
• we want to send state-changing commands
• the operation must be performed eventually, even if it fails
the first couple times
• we don’t care about potentially complex message structure
When to use which Approach?
• We might want to use Transactional Messaging if:
• we want to send state-changing commands only when the
local database transaction has been successful
• two-phase commit is not an option
• we don’t trust the message broker (actually, better look for
one you trust)
When to use which Approach?
• We might want to use Zero Payload Events if:
• we want to send state-changing commands
• we would otherwise have a very complex message structure
that is hard to maintain in a backwards-compatible way
Suggested Reading
• https://www.oreilly.com/library/view/building-microservices-2nd/978
1492034018/ch04.html