Slide 1

Slide 1 text

Micro A microservice toolkit

Slide 2

Slide 2 text

Bio Asim Aslam Mostly build platforms Micro Enjoy all things scale Hailo Write lots of cruft Google asimaslam.com @chuhnk

Slide 3

Slide 3 text

What is Micro?

Slide 4

Slide 4 text

Micro is too many things... Framework… toolkit… library… community… company… It’s a toolkit! It’s an ecosystem! It’s an overloaded term...sorry! Let’s just talk about the toolkit

Slide 5

Slide 5 text

A microservice toolkit A set of building blocks {discovery, communication, etc} Simplifying distributed systems Pluggable framework Sane defaults Low barrier to entry Avoids magic

Slide 6

Slide 6 text

Wait...microservices?

Slide 7

Slide 7 text

Microservices “Loosely coupled service oriented architecture with a bounded context” @adrianco

Slide 8

Slide 8 text

“Turning a big ball of cruft into smaller balls of cruft which communicate over a network” @chuhnk

Slide 9

Slide 9 text

Monolith Microservices

Slide 10

Slide 10 text

OK... but why?

Slide 11

Slide 11 text

So many reasons 1. The monolith becomes brittle as it grows 2. Most large scale systems are naturally distributed 3. Teams are easier to scale with microservices 4. Faster development cycles 5. Independently managed services 6. More enjoyable to write 7. So many more reasons 8. Do you really like monoliths? 9. Insert more reasons here

Slide 12

Slide 12 text

But to be clear There are tradeoffs.

Slide 13

Slide 13 text

Why a toolkit?

Slide 14

Slide 14 text

Building distributed systems is still hard.

Slide 15

Slide 15 text

Distributed Systems Fallacies 1. The network is reliable 2. Latency is zero 3. Bandwidth is infinite 4. The network is secure 5. Topology doesn’t change 6. There is one administrator 7. Transport code is zero 8. The network is homogeneous

Slide 16

Slide 16 text

The cloud will not save us...

Slide 17

Slide 17 text

Containers will not save us...

Slide 18

Slide 18 text

How do I actually write distributed systems?

Slide 19

Slide 19 text

The Origin Story

Slide 20

Slide 20 text

The Motivation 2014 Nothing really out there Enjoyed the Hailo way of building services We had no plans to open source at the time Everyone was building the same thing over and over Wanted to rally around one OSS effort

Slide 21

Slide 21 text

Humble Beginnings Started with go-micro A pluggable RPC framework Service discovery, encoding, synch/asynch communication Leveraged youtube/vitess/rpcplus Open sourced January 2015

Slide 22

Slide 22 text

Evolved into a toolkit Lots of plugins for go-micro Multiple companies in production Sponsored by Sixt Working full time on Micro Present Day

Slide 23

Slide 23 text

The Go Landscape

Slide 24

Slide 24 text

The Past 2014 net/http net/rpc gorilla/rpc kite custom in-house framework ???

Slide 25

Slide 25 text

The Present 2016 gizmo net/http go-kit net/rpc gRPC gorilla/rpc micro in-house frameworks Plus many more!

Slide 26

Slide 26 text

Beyond Go Netflix OSS Java Seneca Node.JS Nameko Python Finagle JVM Linkerd Agnostic

Slide 27

Slide 27 text

The Micro Toolkit

Slide 28

Slide 28 text

The Toolkit github.com/micro/micro Fundamental Building blocks Go-micro (RPC Framework) Sidecar (HTTP Proxy) API (HTTP => RPC) Web (UI + Proxy) CLI (Terminal) Bot (Hubot)

Slide 29

Slide 29 text

go-micro github.com/micro/go-micro Pluggable RPC framework Strongly defined interfaces Addresses core requirements for microservices Sane defaults; consul, http, {json, proto}-rpc Extensible via wrappers/middleware

Slide 30

Slide 30 text

go-micro features Service discovery Message encoding RPC client/server Request-Response Publish-Subscribe Client side load balancing Service Client Server Transport Selector Registry Codec Broker

Slide 31

Slide 31 text

Pluggable

Slide 32

Slide 32 text

Interfaces A way to specify the behavior of an object If something can do this then it can be used here

Slide 33

Slide 33 text

Registry Service Discovery type Registry interface { Register(*Service, ...RegisterOption) error Deregister(*Service) error GetService(string) ([]*Service, error) ListServices() ([]*Service, error) Watch() (Watcher, error) String() string }

Slide 34

Slide 34 text

Consul Implement the interface type consulRegistry struct {} func (c *consulRegistry) Register(*Service, ...RegisterOption) error {…} func (c *consulRegistry) Deregister(*Service) error {…} func (c *consulRegistry) GetService(string) ([]*Service, error) {…} func (c *consulRegistry) ListServices() ([]*Service, error) {…} func (c *consulRegistry) Watch() (Watcher, error) {…} func (c *consulRegistry) String() string { return "consul" } func NewRegistry(...Option) Registry { return &consulRegistry{} }

Slide 35

Slide 35 text

Transport Request-Response type Transport interface { Dial(addr string, opts ...DialOption) (Client, error) Listen(addr string, opts ...ListenOption) (Listener, error) String() string } type Listener interface { Addr() string Close() error Accept(func(Socket)) error }

Slide 36

Slide 36 text

Mock Testing type mockTransport struct {} func (m *mockTransport) Dial(string, ...DialOption) (Client, error) {…} func (m *mockTransport) Listen(string, ...ListenOption) (Listener, error) {…} func (m *mockTransport) String() string { return "mock" } func NewTransport(opts ...Option) Transport { return &mockTransport{} }

Slide 37

Slide 37 text

Writing a service

Slide 38

Slide 38 text

go-micro define API syntax = "proto3"; service Greeter { rpc Hello(Request) returns (Response) {} } message Request { string name = 1; } message Response { string greeting = 1; }

Slide 39

Slide 39 text

go-micro define handler import "github.com/path/to/proto" type Greeter struct{} func (g *Greeter) Hello( ctx context.Context, request *proto.Request, response *proto.Response, ) error { response.Greeting = "Hello " + request.Name return nil }

Slide 40

Slide 40 text

go-micro create service service := micro.NewService( micro.Name("com.example.srv.greeter"), micro.Version("1.0.0"), ) service.Init() proto.RegisterGreeterHandler(service.Server(), new(Greeter)) if err := service.Run(); err != nil { log.Fatal(err) }

Slide 41

Slide 41 text

go-micro call service greeter := proto.NewGreeterClient("com.example.srv.greeter", service.Client()) response, err := greeter.Hello(context.TODO(), &proto.Request{ Name: "John" }) if err != nil { // Blurgh?!? } fmt.Println(response.Greeting)

Slide 42

Slide 42 text

Beneath the covers

Slide 43

Slide 43 text

go-micro service.Run Generate service definition Register with service discovery Listen and accept requests Decode and handle requests Optionally heartbeat with discovery

Slide 44

Slide 44 text

go-micro client.Call(“service”) Request encoding Service lookup Node selection Connection pooling Retries, timeouts, backoff Oh and making the request

Slide 45

Slide 45 text

What about rate limiting, circuit breaking, authentication, etc

Slide 46

Slide 46 text

Wrappers

Slide 47

Slide 47 text

Decorator Pattern A design pattern that allows behavior to be added to an individual object, without affecting the behavior of other objects

Slide 48

Slide 48 text

Client or Handler Authentication Circuit breaking Rate limiting Logging Event notifications Instrumentation Context injection

Slide 49

Slide 49 text

go-micro wrappers client type Wrapper func(Client) Client server type HandlerWrapper func(HandlerFunc) HandlerFunc … service := micro.NewService( micro.Name("com.example.srv.foobar"), micro.WrapClient(breakerClientWrapper), micro.WrapHandler(rateLimiterHandlerWrapper), )

Slide 50

Slide 50 text

How do I access these things externally?

Slide 51

Slide 51 text

Entry Points

Slide 52

Slide 52 text

Sidecar > micro sidecar Replicates the features of go-micro as a HTTP interface Can be used as a proxy for the CLI with --proxy_address

Slide 53

Slide 53 text

API > micro api External gateway API service layer HTTP => RPC or Reverse Proxy Path based resolution /[service]/[method] Zero config

Slide 54

Slide 54 text

API > micro api

Slide 55

Slide 55 text

Web > micro web Dashboard Proxy Web apps as microservices First class citizens

Slide 56

Slide 56 text

CLI > micro get service $ micro get service go.micro.srv.greeter service go.micro.srv.greeter version 1.0.0 Id Address Port Metadata go.micro.srv.greeter-e081eb6a-325f-11e6-8303-68a86d0d36b6 192.168.1.64 62628 server=rpc,registry=consul,transport=http,broker=http Endpoint: Say.Hello Metadata: stream=false Request: { name string } Response: { msg string }

Slide 57

Slide 57 text

Bot > micro bot CLI features via messaging Supports slack and hipchat Pluggable Inputs and Commands Messaging is an entry point like the API, CLI, etc

Slide 58

Slide 58 text

What’s next?

Slide 59

Slide 59 text

Platform “A microservice platform” github.com/micro/go-platform Higher level requirements Authentication Dynamic configuration Distributed tracing Metrics Monitoring Structured logging Synchronisation

Slide 60

Slide 60 text

Plugins “Implement the interface” github.com/micro/go-plugins Swap out backends broker/kafka registry/etcd transport/nats Plus many more! Contributions welcome!

Slide 61

Slide 61 text

Community “Share the journey” slack.micro.mu All things microservices Discuss micro Discuss microservices Discuss production use Discuss the tradeoffs

Slide 62

Slide 62 text

Multi Language {go, js, java, rs}-micro Multi language support Full implementation? Lightweight client? Use the Sidecar? Help wanted!

Slide 63

Slide 63 text

Thanks! Questions? micro.mu @microhq github.com/micro