Lesson 1

Microservices & Programming the first API with Java

Share Tweet


  1. Resources
  2. Part 1: Microservices
  3. Part 2: API Programming with Java
  4. Further Reading


  • Chapter 1: Microservices [PDF]
  • API Programming with Java - A Hello World Project

Part 1: Microservices

(Extracted from "Sam Newman. Building Microservices. O'Reilly Media, Inc., 2021.")

Microservices are independently releasable services that are modeled around a business domain. A service encapsulates functionality and makes it accessible to other services via networks - you construct a more complex system from these building blocks. One microservice might represent inventory, another order management, and yet another shipping, but together they might constitute an entire ecommerce system. Microservices are an architecture choice that is focused on giving you many options for solving the problems you might face.

They are a type of service-oriented architecture, albeit one that is opinionated about how service boundaries should be drawn, and one in which independent deployability is key. They are technology agnostic, which is one of the advantages they offer.

From the outside, a single microservice is treated as a black box. It hosts business functionality on one or more network endpoints (for example, a queue or a REST API, as shown in below figure), over whatever protocols are most appropriate. Consumers, whether they're other microservices or other sorts of programs, access this functionality via these networked endpoints. Internal implementation details (such as the technology the service is written in or the way data is stored) are entirely hidden from the outside world. This means microservice architectures avoid the use of shared databases in most circumstances; instead, each microservice encapsulates its own database where required.

Fig 1. A microservice exposing its functionality over a REST API and a topic [1]
Fig 1. A microservice exposing its functionality over a REST API and a topic [1]

Microservices embrace the concept of information hiding. Information hiding means hiding as much information as possible inside a component and exposing as little as possible via external interfaces. This allows for clear separation between what can change easily and what is more difficult to change. Implementation that is hidden from external parties can be changed freely as long as the networked interfaces the microservice exposes don't change in a backward-incompatible fashion. Changes inside a microservice boundary (as shown in Fig. 1) shouldn't affect an upstream consumer, enabling independent releasability of functionality. This is essential in allowing our microservices to be worked on in isolation and released on demand. Having clear, stable service boundaries that don't change when the internal implementation changes results in systems that have looser coupling and stronger cohesion.

Part 2: API Programming with Java

In the second part of this lesson, we will have a hands-on practice to implement an Java API. The objective of this tutorial is to help you to get familiar with programming APIs, especially understand the idea of microservices architecture.

This second part is available at https://cs504070.duonghuuphuc.com/lesson-01/api-programming-with-java.html

Further Reading

  1. Building Microservices (Sam Newman) [2021] — Chapter 1 - What Are Microservices?
  2. Microservice Trade-Offs (Martin Fowler) [2015]
  3. Microservices - Not A Free Lunch! (Benjamin Wootton) [2014]
  4. DevOps Defined (Thomas Kurian Theakanath) [2016]