golang-microservices-20171109
golang-microservices-20171109
ERIK LUPANDER
2017-11-09 | CALLISTAENTERPRISE.SE
ABOUT ME
2
Love at first sight!
3
ON THE AGENDA…
4
THE FOOTPRINT PROBLEM
5
THE FOOTPRINT PROBLEM
6
THE GO LANGUAGE
The Go Language
7
THE GO LANGUAGE
8
THE GO LANGUAGE
9
THE GO LANGUAGE
Go was designed …
10
THE GO LANGUAGE
Go official FAQ
11
WHAT WAS IMPROVED WITH GO?
12
THE GO LANGUAGE
• Claims to be
• efficient, scalable and productive.
• Designed
• to improve the working environment for its designers and
their coworkers.
• Is not
• a research language.
13
THE GO LANGUAGE
• Go is
• compiled, statically typed, concurrent, garbage-collected
• Has
• structs, pointers, interfaces, closures
• But does not have
• classes, inheritance, generics, operator overloading, pointer
arithmetic
14
WHY GOLANG - DEVELOPING
15
”… a disservice to intelligent programmers”
Gary Willoughby - blogger
16
”… stuck in the 70’s”
Dan Given
17
”… psuedointellectual arrogance of Rob Pike
and everything he stands for”
Keith Wesolowski
18
THE GO LANGUAGE
But also
19
”I like a lot of the design decisions they made in the [Go] language.
Basically, I like all of them.”
Martin Odersky, creator of Scala
20
”Never used a language before that empowers you to solve problems
as quick as Go does”
Alexander Orlov @ Twitter
21
”Go isn’t a very good language in theory, but it’s a great language in
practice, and practice is all I care about”
anonymous hackernews poster
22
THE GO LANGUAGE
23
DEVELOPMENT IN GOLANG - PROS
24
DEVELOPING IN GOLANG - SOME CONS
• Missing generics
• Dependency versioning
• Verbose syntax
• Error checking, no autoboxing of primitive types etc.
• Unit testing and Mocking isn’t very intuitive.
25
WHO USES GOLANG
26
GOLANG - SYNTAX IN 2-5 MINUTES
27
SAMPLE CODE 1 - HELLO WORLD
28
SAMPLE CODE 2 - CONCURRENCY
29
Go microservices
30
GO MICROSERVICE IMPLEMENTATION - CONSIDERATIONS
31
The demo application
32
Curl Legend
ARCHITECTURAL OVERVIEW • CB = Circuit Breaker (Go Hystrix)
• TA = Correlated tracing (Opentracing API / Zipkin)
HTTPS
Docker Swarm
cluster Edge server
OAuth token relay
(Netflix Zuul)
CB/TA
HTTP
HTTP
Configuration Hystrix Stream
Server Account Composite (Go) aggregation
(spring-cloud- AMQP (Modified Netflix
config) TA Turbine)
CB / TA
VipService (Go)
AMQP Trace
HTTP
Messaging HTTP Analysis
(RabbitMQ) (Zipkin)
TA
34
GO MICROSERVICES - STATICALLY LINKED BINARIES
35
DOCKER CONTAINERS & STATICALLY LINKED BINARIES
FROM iron/base
EXPOSE 6868
ADD vipservice-linux-amd64 /
ADD healthcheck-linux-amd64 /
36
Demo 1
Footprint @ Docker Swarm Mode
37
”what is hard in Microservices is all the things
around them”
Jonas Bonér - author of Akka
38
Consider:
39
MICROSERVICE CONSIDERATIONS
• Centralized configuration
• Service Discovery
• Centralized Logging
• Distributed Tracing
• Circuit Breaking
• Load balancing
• Edge server / Reverse proxy
• Monitoring
• Security
40
Curl Legend
ARCHITECTURAL OVERVIEW • CB = Circuit Breaker (Go Hystrix)
• TA = Correlated tracing (Opentracing API / Zipkin)
HTTPS
Docker Swarm
cluster Edge server
OAuth token relay
(Netflix Zuul)
CB/TA
HTTP
HTTP
Configuration Hystrix Stream
Server Account Composite (Go) aggregation
(spring-cloud- AMQP (Modified Netflix
config) TA Turbine)
CB / TA
VipService (Go)
AMQP Trace
HTTP
Messaging HTTP Analysis
(RabbitMQ) (Zipkin)
TA
42
EDGE SERVER
43
SERVICE DISCOVERY AND LOAD BALANCING
44
Demo 2 -
Load balancing and fast scaling
@ Docker Swarm
45
Go Microservice
Anatomy
TA
46
HTTP / REST FRAMEWORK
HTTP/REST framework
(gorilla)
Configuration Trace
Server Configuration Distributed
Analysis
(spring-cloud- Client Tracing
(Zipkin)
config) (viper) (opentracing-go)
Logger
(logrus)
47
GO WITH OUT WITHOUT WEB FRAMEWORKS?
48
HTTP FRAMEWORK (GORILLA)
49
HTTP FRAMEWORK (GORILLA)
50
CENTRALIZED CONFIGURATION
HTTP/REST framework
(gorilla)
Configuration Trace
Server Configuration Distributed
Analysis
(spring-cloud- Client Tracing
(Zipkin)
config) (viper) (opentracing-go)
Logger
(logrus)
51
CENTRALIZED CONFIGURATION
52
CONFIGURATION USING SPRING CLOUD CONFIG AND VIPER
Docker Swarm
Microservices
VIPER
CB / TA
http://configserver:8888/imageservice-test/master
53
CONFIGURATION - VIPER
54
CONFIGURATION - VIPER USAGE
55
CONFIGURATION PUSH USING SPRING CLOUD CONFIG AND VIPER
Configuration
git HTTP POST commit hook
Server
repository (spring-cloud-config) VIPER
CB / TA VIPER
<Refresh token> CB / TA
<Refresh token>
RabbitMQ
56
Demo 3 -
Configuration Push
57
CENTRALIZED LOGGING
HTTP/REST framework
(gorilla)
Configuration Trace
Server Configuration Distributed
Analysis
(spring-cloud- Client Tracing
(Zipkin)
config) (viper) (opentracing-go)
Logger
(logrus)
58
LOGGING - LOGRUS
59
LOGRUS
60
CENTRALIZING LOGS
61
LOGGING WITH CONTAINER METADATA (GELF)
{
"version":"1.1",
"host":"swarm-manager-0",
"short_message":{
”level”:"info",
"msg":"Successfully initialized service”,
”time":"2017-07-17T16:03:35+02:00"
},
"timestamp":1.487625824614e+09,
"level":6,
"_command":"./vipservice-linux-amd64 -profile=test",
”_container_id”:”894edfe2faed131d417eebf77306a0386b430….",
"_container_name":"vipservice.1.jgaludcy21iriskcu1fx9nx2p",
"_created":"2017-02-20T21:23:38.877748337Z",
”_image_id”:”sha256:1df84e91e0931ec14c6fb4e55…..”,
"_image_name":"someprefix/vipservice:latest",
"_tag":"894edfe2faed"
}
62
63
DISTRIBUTED TRACING
HTTP/REST framework
(gorilla)
Configuration Trace
Server Configuration Distributed
Analysis
(spring-cloud- Client Tracing
(Zipkin)
config) (viper) (opentracing-go)
Logger
(logrus)
64
DISTRIBUTED TRACING
65
GO-OPENTRACING CODE SAMPLE
66
DISTRIBUTED TRACING
67
Demo 4 -
Distributed Tracing with Zipkin
68
CIRCUIT BREAKER
HTTP/REST framework
(gorilla)
Configuration Trace
Server Configuration Distributed
Analysis
(spring-cloud- Client Tracing
(Zipkin)
config) (viper) (opentracing-go)
Logger
(logrus)
69
CIRCUIT BREAKING - HYSTRIX
70
CIRCUIT BREAKING
71
CIRCUIT BREAKING
72
CIRCUIT BREAKING
:8181/hystrix.stream
CB / TA
:8181/hystrix.stream
CB / TA
RabbitMQ
73
Demo 5 -
Hystrix Dashboard
74
DISTRIBUTED TRACING
75
SUMMARY
76
WANT TO LEARN MORE?
• Nic Jackson
• July 2017 from Packt
• Technical reviewers:
• Magnus Larsson
• Erik Lupander
77
DVIZZ - A DOCKER SWARM VISUALIZER
• https://github.com/eriklupander/dvizz
• Pull requests are more than welcome!
78
RESOURCES
79
Questions?
80