Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Micro - A microservice toolkit

Micro - A microservice toolkit

Micro is a toolkit that provides the fundamental building blocks for writing and managing microservices. The slides are from the Go meetup in London on June 15th 2016.

Asim Aslam

June 15, 2016
Tweet

More Decks by Asim Aslam

Other Decks in Programming

Transcript

  1. Bio Asim Aslam Mostly build platforms Micro Enjoy all things

    scale Hailo Write lots of cruft Google asimaslam.com @chuhnk
  2. 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
  3. A microservice toolkit A set of building blocks {discovery, communication,

    etc} Simplifying distributed systems Pluggable framework Sane defaults Low barrier to entry Avoids magic
  4. “Turning a big ball of cruft into smaller balls of

    cruft which communicate over a network” @chuhnk
  5. 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
  6. 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
  7. 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
  8. Humble Beginnings Started with go-micro A pluggable RPC framework Service

    discovery, encoding, synch/asynch communication Leveraged youtube/vitess/rpcplus Open sourced January 2015
  9. Evolved into a toolkit Lots of plugins for go-micro Multiple

    companies in production Sponsored by Sixt Working full time on Micro Present Day
  10. 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)
  11. 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
  12. 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
  13. Interfaces A way to specify the behavior of an object

    If something can do this then it can be used here
  14. 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 }
  15. 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{} }
  16. 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 }
  17. 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{} }
  18. go-micro define API syntax = "proto3"; service Greeter { rpc

    Hello(Request) returns (Response) {} } message Request { string name = 1; } message Response { string greeting = 1; }
  19. 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 }
  20. 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) }
  21. 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)
  22. go-micro service.Run Generate service definition Register with service discovery Listen

    and accept requests Decode and handle requests Optionally heartbeat with discovery
  23. Decorator Pattern A design pattern that allows behavior to be

    added to an individual object, without affecting the behavior of other objects
  24. 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), )
  25. 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
  26. API > micro api External gateway API service layer HTTP

    => RPC or Reverse Proxy Path based resolution /[service]/[method] Zero config
  27. 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 }
  28. 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
  29. Platform “A microservice platform” github.com/micro/go-platform Higher level requirements Authentication Dynamic

    configuration Distributed tracing Metrics Monitoring Structured logging Synchronisation
  30. Community “Share the journey” slack.micro.mu All things microservices Discuss micro

    Discuss microservices Discuss production use Discuss the tradeoffs
  31. Multi Language {go, js, java, rs}-micro Multi language support Full

    implementation? Lightweight client? Use the Sidecar? Help wanted!