Search Sreeni's Insights

Filter by content type
technical June 23, 2016 7 min read

Microservices - Part 1

Microservices Part 1 explains Conway's Law, modular monoliths, service ownership, distributed data, deployment independence and the hidden costs of service boundaries.

Share:

Microservices - Part 1

Microservices are often being presented as a solution to every scaling and team problem. In reality, a microservice is a boundary which is bringing useful independence together with distributed-system cost. In the related 2015 article, we discussed whether a small team should start with microservices, which is a useful reminder that the architecture must be earned by the problem. In this article, we are going to discuss what changes from a monolith to microservices, why teams are considering it and the hidden costs which must be accepted.

TL;DR Summary

  • A microservice is an independently deployable process around a focused business capability.
  • The important boundary is ownership and autonomy, not the number of projects.
  • A modular monolith can be a healthy architecture when the domain and team are small.
  • Conway’s Law is reminding us that system boundaries are influenced by team communication boundaries.
  • Microservices are creating network, distributed-data, monitoring and deployment costs.
  • Each service should own a capability and a clear data responsibility.
  • In our case, we extract one meaningful seam only when the problem requires it.

Challenges

The monolith is growing without boundaries

A fund application can begin with UI, search, pricing and documents in one deployable unit. When every change is touching every area, teams are waiting for one release and a small pricing change is carrying document risk. This is a signal to examine boundaries, but it is not automatically a signal to split every class into a service.

Conway’s Law is affecting the architecture

Conway’s Law says that organisations design systems which mirror their communication structures. If one team owns the whole fund platform, a modular monolith can be easier to operate. If separate teams own Search, Pricing and Documents, clear service boundaries may reduce coordination. Splitting code without changing ownership is often creating distributed complexity without autonomy.

The network is replacing a method call

Inside a monolith, a pricing method returns an object or throws an exception in the same process. Between services, the call is travelling through a network which can be slow, unavailable or returning a different version. Timeouts, retries, contracts and tracing are becoming normal business concerns.

What are microservices?

A microservice is an independently deployable process which owns a focused business capability and communicates with other services through explicit contracts.

In simple terms, Search, Pricing and Documents are becoming separate front liners for the Fund Platform. Each can be released by its owner, but it must also be monitored, secured and supported by its owner.

An everyday analogy is a specialist hospital. A cardiology department and a radiology department have different skills and equipment, but a patient journey still needs a referral, a record and coordination. Creating a separate room for every medical task will not improve the hospital.

Why microservices are important?

Microservices are important when independent change, team ownership or scaling characteristics are creating a real constraint in the monolith. They can reduce the blast radius of a release, but they increase the number of things which can fail. The decision must include deployment, data, monitoring and incident response.

The following diagram compares a monolith with microservices:

Monolith versus microservices
Monolith versus microservices

The monolith contains UI, Search, Pricing and Documents with one SQL database. The microservices side has UI, Search, Pricing and Documents services, each with its own data store. The important point is ownership: a service which owns Pricing should own its data contract and its release. It is not enough to create four projects which still share one database schema.

Distributed data

In a monolith, a transaction can update a holding and its audit record. In microservices, Pricing and Documents cannot normally share one transaction without recreating coupling. We must decide whether the interaction is synchronous, event-driven or eventually consistent. A fund price published by Pricing can produce an event which Search consumes later.

Deployment independence

An independent service requires a build, package, configuration, health endpoint, deployment path and rollback. It also requires a compatible contract. The service can deploy independently only when the consumer is not breaking on every internal change. Versioning is therefore part of the boundary.

Hidden costs

The following diagram depicts the costs around the central decision:

Hidden costs of microservices
Hidden costs of microservices

Network latency, distributed data, monitoring, deployment automation, versioning and team skills are the six costs shown around Hidden Costs. The arrows are not showing an input or output flow; they are showing concerns which surround the decision. We should use this diagram as a review checklist.

Monitoring must include a correlation id across HTTP and Service Bus messages. Deployment automation must promote a known artifact to each service. Versioning must say whether an API is backward compatible. Team skills must include debugging a request which is crossing several processes.

A small extraction example

Suppose the monolith has this call:

public FundSummary GetSummary(int fundId)
{
    var fund = _fundRepository.Get(fundId);
    var price = _priceRepository.GetLatest(fundId);
    var documents = _documentRepository.GetPublic(fundId);
    return new FundSummary(fund, price, documents);
}

The first step is not creating three services. We can define a Pricing interface and keep it inside the modular monolith:

public interface IPriceReader
{
    Price GetLatest(int fundId);
}

After the contract is understood, the implementation can move behind an HTTP endpoint or message boundary. The consumer must have a timeout and a useful fallback:

var response = await client.GetAsync("/funds/123/price",
    cancellationToken);
response.EnsureSuccessStatusCode();

The service must not read the Pricing database directly. If it needs a price, it uses the Pricing API or a published read model. This is where distributed data becomes a deliberate choice.

Trade-offs

ApproachProsCons
Modular monolith+ In-process calls and simple deployment<br>+ Easier transactions− Release boundary is shared<br>− Ownership can become unclear
Microservices+ Independent deployment and team ownership<br>+ Capability-specific scaling− Network, data and observability complexity<br>− Higher platform and skill requirement

In our case, we keep a modular monolith while the domain is still new. We extract a Pricing boundary only when the team ownership, contract and data responsibility are clear. The service boundary must earn its operational cost.

A safe migration path

The first extraction is selected by a business seam, not by a folder name. Search may be a good candidate when it has a different scaling profile and can rebuild its index. Pricing is more sensitive because its data is authoritative and a split can change transaction behaviour. Documents may be a useful boundary when the document lifecycle is independent from holdings.

The team first defines an interface and a contract test inside the monolith. A consumer test describes the JSON shape, status codes and error behaviour. The implementation can then move behind HTTP while the contract remains stable. During the transition, the old code is removed only after the new path is observed.

The deployment pipeline is building and releasing the service, its configuration and its monitoring together. A service without an alert is not independent; it is only invisible. The dashboard is showing request rate, latency, error rate, dependency failures and queue age where applicable. The runbook is identifying who owns a failed deployment.

Data migration is handled separately from code migration. A service does not read another service’s private tables just to avoid copying data. If a new read model is required, it is populated from an event or a controlled migration and its lag is measured. The old table is retired only after the ownership decision is complete.

The team is also agreeing how an incident is crossing the boundary. A customer support request for a missing fund price is starting with the public correlation id, then tracing the API Gateway, Pricing service and read model. If the path cannot be followed, the services are independent only on paper. This operational test is often exposing a missing log before a production outage.

The first service is released with a rollback plan. A feature switch can send the fund summary to the old implementation while the new Pricing service is observed. The switch does not replace testing, but it reduces the blast radius when the new boundary has an unexpected dependency.

Must Do and Don’ts

  • Must Do: Define the business capability and owner before creating a service, otherwise the new process will not have a support boundary.
  • Must Do: Give each service a data responsibility, because shared writes are hiding coupling.
  • Must Do: Add correlation ids and health checks, so a request crossing services can be diagnosed.
  • Must Do: Start with one seam and measure deployment or scaling pain, instead of splitting the complete application.
  • Don’t: create a service for every class, otherwise the team will be managing processes rather than capabilities.
  • Don’t: share the same database tables between services, because a schema change will break the promised independence.

Wrap up

In this article, we have looked at Conway’s Law, modular monoliths, service ownership, distributed data, deployment independence and the hidden costs of microservices. The architecture is useful when it is solving a real organisational or domain problem. Thanks for reading this article. In the next article, I will walk you through Microservices - Part 2, including synchronous and asynchronous communication.

Related Posts