What are microservices?
The fire making rule:
● Use more sticks than you think they would be
enough
● Use a little bit smaller sticks than you think would
be enough
Informal definition
Microservices when you have smaller, separated
services as usual
● Many times they are not micro (group of services)
● Many times REST is used (but not always)
● Separated means different process/JVM instances
More formal definition
● “an approach to developing a single application as
a suite of small services,
● each running in its own process
● and communicating with lightweight mechanisms,
often an HTTP resource API.
These services are built around business capabilities
and independently deployable by fully automated
deployment machinery.”
Lewis, Fowler
Microservices vs SOA
Even if the “Microservices != SOA” a very common
statement there are a lot of shared concept.
● Usually we have new tools (using existing solutions
differently) not totally new concept
API gateway
Goals:
● Hide available microservices behind a service
facade pattern
– Routing, Authorization
– Deployment handling, Canary testing
– Logging, SLA
Implementations:
● Spring cloud: Netflix Zuul
● Netflix Zuul based implementation
● Twitter Finagle based implementation
● Amazon API gateway
● Simple Nginx reverse proxy configuration
Spring Cloud + Zuul example
@EnableAutoConfiguration
@ComponentScan
@EnableEurekaClient
@EnableZuulProxy
public class ApiGatewayStarter {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayStarter.class, args);
}
}
Service registry
Goal:
● Store the location and state of the available
services
– Health check
– DNS interface
Implementations:
● Spring cloud: Eureka
● Netflix eureka based implementation
● Consul.io
● etcd, zookeeper
● Simple: DNS or hosts file
Monolith configuration
● Store configuration outside of the project
– Versioning? Who did what
● Store configuration in separated versioned project
– Which binary version need which config version?
● Store configuration with the source code
– Sensitive configuration?
Config Service
Goals:
● One common place for all of the configuration
– Versioning
– Auditing
– Multiple environment support
Solutions:
● Spring Cloud config service
● Zookeeper
● Most of the service registry have key->value store
● Any persistence datastore
Config repository
elek@sc /tmp/config-repo [master] > ls -lah
drwxr-xr-x 3 elek elek 100 Dec 14 14:32 .
drwxrwxrwt 57 root root 1.8K Dec 14 14:37 ..
-rw-r--r-- 1 elek elek 55 Dec 14 14:16 application.properties
drwxr-xr-x 8 elek elek 260 Dec 14 14:40 .git
-rw-r--r-- 1 elek elek 12 Dec 14 14:32 timer.properties
Config client
@Service
public class TimeService {
@Value("${version:Unknown}")
String version;
public Date now() {
return new Date();
}
public String version() {
return version;
}
}
Monitoring
Goal:
● Combined business log
● Health check, exceptions, what is running?
● Metrics
Solutions (for one of the goals):
● Netflix Spectator, Servo, Atlas
● Spring cloud: Hystrix (circuit breaker)
● ELK: ElasticSearch + Logstash + Kibana
● Cloud based solutions (logentries...)
● Metrics: Dropwizard based implementations
Hystrix
@Service
public class TimeService {
@HystrixCommand(fallbackMethod = "safeNow")
public Date now() {
return new Date();
}
public Date safeNow() {
return new Date(0);
}
}
Distributed tracing
Goal:
● Global information about latency and errors
– Service enter/exit point measurement
– Transaction identification
Implementations:
● Twitter’s Zipkin
● Apache (Cloudera) HTrace
● Spring cloud Sleuth
Advantages of microservices
● Modular, loosely coupled
● Easily scalable to multiple machines
● Separated, modular development lifecycle
● Partial deploy without restart [like OSGi]
● Supports heterogeneous architecture (tech stack
migration)
Summary
● Focus on modularity
● Be familiar with the microservice related tools: they
could be useful even with monolith applications…
Start with monolith?
Stefan Tilkov:
http://martinfowler.com/articles/dont-
start-monolith.html
Martin Fowler:
http://martinfowler.com/bliki/MonolithFirst.
html