Microservices consulting and training

Microservices.io is brought to you by Chris Richardson. Experienced software architect, author of POJOs in Action and the creator of the original CloudFoundry.com. His latest startup is eventuate.io, a microservices application platform.

He offers a comprehensive set of resources for learning about microservices including articles, an O'Reilly training video, consulting, workshops and hands on training classes.

Learn More

Example microservices applications

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

The patterns


Signup for the newsletter

A new microservices application platform that solves distributed data management problems.

Join the microservices google group

Pattern: Self Registration

Context

You have applied either the Client-side Service Discovery pattern or the Server-side Service Discovery pattern. Service instances must be registered with the service registry on startup so that they can be discovered and unregistered on shutdown.

Problem

How are service instances registered with and unregistered from the service registry?

Forces

  • Service instances must be registered with the service registry on startup and unregistered on shutdown
  • Service instances that crash must be unregistered from the service registry
  • Service instances that are running but incapable of handling requests must be unregistered from the service registry

Solution

A service instance is responsible for registering itself with the service registry. On startup the service instance registers itself (host and IP address) with the service registry and makes itself available for discovery. The client must typically periodically renew it’s registration so that the registry knows it is still alive. On shutdown, the service instance unregisters itself from the service registry.

This is typically handled by a Microservice chassis framework

Examples

Netflix Eureka is an example of a service registry. It provides a registration API and a client library that service instances use to (un)register themselves.

When using Apache Zookeeper as a service registry, each service corresponds to a particular Zookeeper znode. On startup, each service instance creates an ephemeral child znode of the service znode. The ephemeral znode contains the instance’s location. Clients of the service simply retrieve the children of the service znode in order to determine the available instances. If the client terminates without removing the ephemeral node, Zookeeper will timeout the client and remove the znode.

Resulting context

The benefits of the Self Registration pattern include the following:

  • A service instance knows it’s own state so can implement a state model that’s more complex than UP/DOWN, e.g. STARTING, AVAILABLE, …

There are also some drawbacks:

  • Couples the service to the Service Registry
  • You must implement service registration logic in each programming language/framework that you use to write your services, e.g. NodeJS/JavaScript, Java/Scala, etc.
  • A service instance that is running yet unable to handle requests will often lack the self-awareness to unregister itself from the service registry

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