Micro on NATS - microservices with messaging

Micro on NATS - microservices with messaging

Micro on NATS was presented at the London NATS meetup in May.


Asim Aslam

May 14, 2016


  1. Micro on NATS Microservices with messaging

  2. Who am I? Asim Aslam Working on Micro Previously at

    Hailo Before then Google @chuhnk asimaslam.com
  3. What is Micro? A microservice ecosystem Simplifying building and managing

    distributed systems What does that even mean? Building OSS tools that make it easier to write and run micro service applications Written in Go 100% Open Source
  4. Micro A Microservice Toolkit Go Micro - Pluggable RPC framework

    for writing microservices API - API gateway. Translates HTTP to RPC. Path-to-Service resolution Web - Dashboard and reverse proxy. Web apps as first class citizens CLI - Command line interface. Straight forward. No frills. Sidecar - HTTP interface with all the features of Go Micro Bot - Hubot style bot for ChatOps. CLI Features. A bot? Really? Yea dude!
  5. Go Micro RPC Framework Registry - Service Discovery Selector -

    Client side load balancer Transport - Synchronous Communication Broker - Asynchronous Communication Codec - Message encoding Client - RPC Client Server - RPC Server
  6. Why NATS? Built for high performance and scale Highly available

    - client and server side clustering Extremely lightweight - written in Go, no persistence features At most once delivery - fire and forget Simple, focused and made for microservices Written by Derek Collison, with two decades of experience building messaging systems
  7. Micro on NATS NATS Plugins Go-Micro has a pluggable architecture

    Each feature written as a Go interface. Just implement the interface. Integrate NATS using plugins for: Registry - Service Discovery Transport - Synchronous Communication Broker - Asynchronous Communication
  8. Transport Synchronous Communication Handles request-response Supports bidirectional streaming Socket style

    semantics; Send(), Recv(), Close() type Transport interface { Dial(addr string, opts ...DialOption) (Client, error) Listen(addr string, opts ...ListenOption) (Listener, error) String() string }
  9. Transport 1. Server Listen - Subscribes to unique topic, wait

    for pseudo connections 2. Client Dial - Subscribes to unique topic, publishes to Server with reply topic set 3. Server Socket - Pseudo Socket created for every new “connection” 4. Client Socket - Same as server. Send() - Publish, Recv() - Subscribed messages
  10. Broker Asynchronous Communication Publish and Subscribe mechanism Includes notion of

    Topics and Channels (Queues) Distribute messages between subscribers type Broker interface { …. Connect() error Disconnect() error Publish(string, *Message, ...PublishOption) error Subscribe(string, Handler, ...SubscribeOption) (Subscriber, error) String() string }
  11. Broker 1. Subscribe - Register interest to Topic. Specify Queue

    to distribute messages 2. Publish - Asynchronously publish to Topic 3. Encoding - Broker encodes Message to JSON
  12. Registry Service Discovery Service discovery using a message bus? What

    magic is this? type Registry interface { Register(*Service, ...RegisterOption) error Deregister(*Service) error GetService(string) ([]*Service, error) ListServices() ([]*Service, error) Watch() (Watcher, error) String() string }
  13. Broadcast Queries! 1. All services subscribe for queries on a

    broadcast topic 2. Publish query on broadcast topic with reply address 3. Instances of queried service respond 4. Wait for responses until upper time limit 5. Aggregate and return results
  14. Scaling Like A Boss Cluster per AZ or Region Multi-AZ

    deployment Fault tolerant of AZ failure Pattern for high availability Multi-region deployment Use DNS latency based routing
  15. Thanks for listening! Micro on NATS blog post blog.micro.mu/2016/04/11/micro-on-nats.html Micro

    on GitHub Follow on Twitter! github.com/micro @MicroHQ Micro on Web Join the Slack community! micro.mu slack.micro.mu