Microservices and modularity with
Java
Elek Márton
@anzix
2015 December
DPC Consulting
Agenda
● Microservice definition
● Core implementation patterns
People need modularity not
microservices
Microservices is one way to achieve
modularity.
Other ways: OSGi, SPI, java9 jigsaw
What are microservices?
The fire making rule:
● Use more sticks than you think they would be
enough
● Use a little bit sma...
Informal definition
Microservices when you have smaller, separated
services as usual
● Many times they are not micro (grou...
More formal definition
● “an approach to developing a single application as
a suite of small services,
● each running in i...
Microservices and REST
REST is just one solution to communicate
● between services
● or call any of the service
Microservices vs SOA
Even if the “Microservices != SOA” a very common
statement there are a lot of shared concept.
● Usual...
Implementation patterns
Monolith application
Spring boot example
@EnableAutoConfiguration
@RestController
@ComponentScan
public class TimeStarter {
@Autowired
TimeServ...
Modular monolith
API gateway
API gateway
Goals:
● Hide available microservices behind a service
facade pattern
– Routing, Authorization
– Deployment ha...
Spring Cloud + Zuul example
@EnableAutoConfiguration
@ComponentScan
@EnableEurekaClient
@EnableZuulProxy
public class ApiG...
Service registry
Service registry
Goal:
● Store the location and state of the available
services
– Health check
– DNS interface
Implementat...
Eureka
Eureka server
@SpringBootApplication
@EnableEurekaServer
public class EurekaStarter {
public static void main(String[] arg...
Eureka client
@EnableAutoConfiguration
@RestController
@ComponentScan
@EnableEurekaClient
public class TimeStarter {
@Auto...
SIMPLE Discovery client
@Service
public class Client {
@Autowired
private DiscoveryClient discoveryClient;
public void lis...
Config service
Monolith configuration
● Store configuration outside of the project
– Versioning? Who did what
● Store configuration in se...
Config Service
Goals:
● One common place for all of the configuration
– Versioning
– Auditing
– Multiple environment suppo...
Config server
@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
public class ConfigServer {
public static voi...
Config repository
elek@sc /tmp/config-repo [master] > ls -lah
drwxr-xr-x 3 elek elek 100 Dec 14 14:32 .
drwxrwxrwt 57 root...
Config client
@Service
public class TimeService {
@Value("${version:Unknown}")
String version;
public Date now() {
return ...
Monitoring
Monitoring
Goal:
● Combined business log
● Health check, exceptions, what is running?
● Metrics
Solutions (for one of the ...
Kibana (from ELK)
Hystrix
Hystrix
@Service
public class TimeService {
@HystrixCommand(fallbackMethod = "safeNow")
public Date now() {
return new Dat...
Inter-module calls
Inter-module calls
Inter-module calls
Goal:
● RPC calls between modules
● Protocol
● Usage of the Service Registry
Solutions:
● Spring cloud/...
Distributed tracing
Distributed tracing (simlified)
Distributed tracing
Goal:
● Global information about latency and errors
– Service enter/exit point measurement
– Transacti...
Zipkin
source: https://bitbucket.org/aktivecortex/aktivecortex/wiki/tracing.md
Summary
Advantages of monolith
Modular monolith Microservices
Advantages of microservices
● Modular, loosely coupled
● Easily scalable to multiple machines
● Separated, modular develop...
Summary
● Focus on modularity
● Be familiar with the microservice related tools: they
could be useful even with monolith a...
Start with monolith?
Stefan Tilkov:
http://martinfowler.com/articles/dont-
start-monolith.html
Martin Fowler:
http://marti...
Q&A
Márton Elek
DPC consulting http://dpc.hu
twitter: @anzix
http://blog.dpc.hu, http://blog.anzix.net
Microservices and modularity with java
Microservices and modularity with java
Upcoming SlideShare
Loading in …5
×

Microservices and modularity with java

430 views

Published on

Short introuduction about microservices and java
Author: Marton Elek, DPC Consulting

Published in: Engineering
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
430
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Microservices and modularity with java

  1. 1. Microservices and modularity with Java Elek Márton @anzix 2015 December DPC Consulting
  2. 2. Agenda ● Microservice definition ● Core implementation patterns
  3. 3. People need modularity not microservices
  4. 4. Microservices is one way to achieve modularity. Other ways: OSGi, SPI, java9 jigsaw
  5. 5. 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
  6. 6. 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
  7. 7. 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
  8. 8. Microservices and REST REST is just one solution to communicate ● between services ● or call any of the service
  9. 9. 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
  10. 10. Implementation patterns
  11. 11. Monolith application
  12. 12. Spring boot example @EnableAutoConfiguration @RestController @ComponentScan public class TimeStarter { @Autowired TimeService timerService; @RequestMapping("/now") public Date now() { return timerService.now(); } public static void main(String[] args) { SpringApplication.run(TimeStarter.class, args); } }
  13. 13. Modular monolith
  14. 14. API gateway
  15. 15. 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
  16. 16. Spring Cloud + Zuul example @EnableAutoConfiguration @ComponentScan @EnableEurekaClient @EnableZuulProxy public class ApiGatewayStarter { public static void main(String[] args) { SpringApplication.run(ApiGatewayStarter.class, args); } }
  17. 17. Service registry
  18. 18. 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
  19. 19. Eureka
  20. 20. Eureka server @SpringBootApplication @EnableEurekaServer public class EurekaStarter { public static void main(String[] args) { new SpringApplicationBuilder(EurekaStarter.class).web(true).run(args); } }
  21. 21. Eureka client @EnableAutoConfiguration @RestController @ComponentScan @EnableEurekaClient public class TimeStarter { @Autowired TimeService tttService; @RequestMapping("/now") public Date now() {return tttService.now();} public static void main(String[] args) { SpringApplication.run(TimeStarter.class, args); } }
  22. 22. SIMPLE Discovery client @Service public class Client { @Autowired private DiscoveryClient discoveryClient; public void list() { for (ServiceInstance instance : discoveryClient.getInstances("BOOTSTRAP")) { System.out.println(instance.getHost()); System.out.println(instance.getPort()); System.out.println(instance.getUri()); } } }
  23. 23. Config service
  24. 24. 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?
  25. 25. 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
  26. 26. Config server @SpringBootApplication @EnableConfigServer @EnableEurekaClient public class ConfigServer { public static void main(String[] args) { new SpringApplicationBuilder(ConfigServer.class).run(args); } }
  27. 27. 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
  28. 28. Config client @Service public class TimeService { @Value("${version:Unknown}") String version; public Date now() { return new Date(); } public String version() { return version; } }
  29. 29. Monitoring
  30. 30. 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
  31. 31. Kibana (from ELK)
  32. 32. Hystrix
  33. 33. Hystrix @Service public class TimeService { @HystrixCommand(fallbackMethod = "safeNow") public Date now() { return new Date(); } public Date safeNow() { return new Date(0); } }
  34. 34. Inter-module calls
  35. 35. Inter-module calls
  36. 36. Inter-module calls Goal: ● RPC calls between modules ● Protocol ● Usage of the Service Registry Solutions: ● Spring cloud/Netflix: ribbon ● Simple REST calls ● Message Oriented solutions: – Rabbit MQ, ZMQ, ...
  37. 37. Distributed tracing
  38. 38. Distributed tracing (simlified)
  39. 39. 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
  40. 40. Zipkin source: https://bitbucket.org/aktivecortex/aktivecortex/wiki/tracing.md
  41. 41. Summary
  42. 42. Advantages of monolith Modular monolith Microservices
  43. 43. 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)
  44. 44. Summary ● Focus on modularity ● Be familiar with the microservice related tools: they could be useful even with monolith applications…
  45. 45. Start with monolith? Stefan Tilkov: http://martinfowler.com/articles/dont- start-monolith.html Martin Fowler: http://martinfowler.com/bliki/MonolithFirst. html
  46. 46. Q&A Márton Elek DPC consulting http://dpc.hu twitter: @anzix http://blog.dpc.hu, http://blog.anzix.net

×