What’s a service - part 1?

The microservice architecture (sometimes abbreviated to microservices) is an architectural style that structures an application as a collection of services that are organized around business capabilities. It enables the continuous delivery/deployment of large, complex applications. The microservice architecture has several other benefits including better scalability, and fault tolerance. It also makes it easier for an organization to experiment with new technologies and evolve its technology stack.

The most critical architectural decision that you must make when using microservices is to identify and design the services and determine how they collaborate. In comparison, technology-related issues, such as Serverless, Docker and Kubernetes, pale into insignificance. This is the first of several posts that explores the nature of a service.

Key characteristics of a service

A service has several key characteristics:

  • Highly maintainable and testable - enables rapid and frequent development and deployment
  • Loosely coupled with other services - enables a team to work independently the majority of time on their service(s) without being impacted by changes to other services and without affecting other services
  • Independently deployable - enables a team to deploy their service without having to coordinate with other teams
  • Capable of being developed by a small team - essential for high productivity by avoiding the high communication overhead of large teams

The structure of a service

The following diagram shows the structure of a service. It has a hexagonal architecture. The core of the service is its business logic, which is surrounded by adapters that communicate with other services and applications.

Let’s look at each part of the service.

A service has an API

From the perspective of its consumers, the only thing that matters about a service is its API. A service API consists of operations and published events.

Operations

There are two types of operations: commands and queries. A command is an operation that mutates data. A query is a command that retrieves data. For example, in the FTGO application, which is my book’s example application, the Order Service, implements commands, such as createOrder(), reviseOrder() and cancelOrder(), and queries, such as findOrder() and findOrderHistory().

A service’s operations are invoked using some combination of synchronous protocols, such as REST or gRPC, and asynchronous messaging. Synchronous protocols, especially REST, are particularly useful when implementing APIs for external clients, such as mobile applications and Single Page applications.

However, asynchronous protocols are typically needed when implementing sagas, which maintain data consistency between services. For example, the FTGO Order Service’s createOrder() operation is implemented by the POST /orders REST endpoint and initiates the Create Order Saga, which is implemented using asynchronous messaging.

Events

A service often publishes events. An event is typically DDD domain events, which are emitted by an aggregate when it’s created, updated or deleted. A service publishes events to a message channel implemented by a message broker. The Eventuate Tram framework, for example, supports publishing events to Apache Kafka, ActiveMQ and RabbitMQ.

Business logic

The heart of the service and the reason for its existence. It implements the API’s operations and publishes events. The business logic invokes the operations of other services and subscribes to their events. It persists data in the service’s database.

A service might collaborate with other services

When services collaborate, it’s through APIs rather than via the database. A service might invoke the operations of another service. The FTGO Order Service, for example, asynchronously invokes the Kitchen Service services.

A service can also subscribe to the events published by another service. The Order Service, for example, subscribes to events published by the Restaurant Service.

A service’s database is private

A service usually has a database, which stores its data and sometimes data replicated from other services. For example, the FTGO Order Service’s database stores Orders as well as Restaurants, which are replicated from the Restaurant Service. In order to ensure loose coupling, it’s generally a bad idea for services to share database tables. Instead, services must only communicate through their APIs.

In later posts, I’ll dig deeper into the nature of a service.

To Learn more



Copyright © 2023 Chris Richardson • All rights reserved • Supported by Kong.

About Microservices.io

Microservices.io is brought to you by Chris Richardson. Experienced software architect, author of POJOs in Action, the creator of the original CloudFoundry.com, and the author of Microservices patterns.

Chris helps clients around the world adopt the microservice architecture through consulting engagements, and training workshops.

Learn how to create a service template and microservice chassis

Take a look at my Manning LiveProject that teaches you how to develop a service template and microservice chassis.

New virtual bootcamp: Distributed data patterns in a microservice architecture

My virtual bootcamp, distributed data patterns in a microservice architecture, is now open for enrollment!

It covers the key distributed data management patterns including Saga, API Composition, and CQRS.

It consists of video lectures, code labs, and a weekly ask-me-anything video conference repeated in multiple timezones.

The regular price is $395/person but use coupon JUNVCEJE to sign up for $195 (valid until February 1st, 2023). There are deeper discounts for buying multiple seats.

Learn more

Signup for the newsletter


LEARN about microservices

Chris offers numerous resources for learning the microservice architecture.

Training classes

Chris teaches comprehensive workshops, training classes and bootcamps for executives, architects and developers to help your organization use microservices effectively.

Avoid the pitfalls of adopting microservices and learn essential topics, such as service decomposition and design and how to refactor a monolith to microservices.

Delivered in-person and remotely.


Get the book: Microservices Patterns

Read Chris Richardson's book:

Example microservices applications

Want to see an example? Check out Chris Richardson's example applications. See code

BUILD microservices

Ready to start using the microservice architecture?

Consulting services

Engage Chris to create a microservices adoption roadmap and help you define your microservice architecture,


The Eventuate platform

Use the Eventuate.io platform to tackle distributed data management challenges in your microservices architecture.

Eventuate is Chris's latest startup. It makes it easy to use the Saga pattern to manage transactions and the CQRS pattern to implement queries.

ASSESS your architecture

Assess your application's microservice architecture and identify what needs to be improved.

Consulting services

Engage Chris to conduct an architectural assessment.



Join the microservices google group

Topics

Note: tagging is work-in-process

anti-patterns   ·  application api   ·  application architecture   ·  architecting   ·  architecture documentation   ·  dark energy and dark matter   ·  deployment   ·  development   ·  devops   ·  docker   ·  implementing commands   ·  implementing queries   ·  inter-service communication   ·  loose coupling   ·  microservice architecture   ·  microservice chassis   ·  microservices adoption   ·  microservicesio updates   ·  multi-architecture docker images   ·  observability   ·  pattern   ·  refactoring to microservices   ·  resilience   ·  sagas   ·  security   ·  service api   ·  service collaboration   ·  service design   ·  service discovery   ·  service granularity   ·  service template   ·  software delivery metrics   ·  success triangle   ·  team topologies   ·  transaction management   ·  transactional messaging

All content


Posts

24 Jul 2017 » Revised data patterns