22
Implementing Microservices with NATS

Implementing Microservices with NATS

  • Upload
    apcera

  • View
    466

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Implementing Microservices with NATS

Implementing Microservices with NATS

Page 2: Implementing Microservices with NATS

Agenda● Microservices● NATS● Aytra● Aytra + NATS● Houston

Page 3: Implementing Microservices with NATS

Microservices

Microservices

Page 4: Implementing Microservices with NATS

Microservices - What?● Micro benefits

○ Flexibility○ Availability○ Security

● Monolithic benefit○ speed?

● Micro challenge○ message passing

Page 5: Implementing Microservices with NATS

Microservices - Why?● Scale application components independently● Roll out features or experiments more freely● Faster iteration● Be aware of challenges

○ API interfaces○ Communication○ Latency○ Tooling

Page 6: Implementing Microservices with NATS

NATS

NATS

Page 7: Implementing Microservices with NATS

NATS - What?● The glue for your microservices● Cloud-native messaging platform● Highly performant● Extremely lightweight● Very flexible

Page 8: Implementing Microservices with NATS

NATS - Why?● Compared to HTTP

○ Built in service discovery○ Built in load balancer○ Simpler & Faster

● Compared to other message queues○ Simpler to implement and operate○ Faster

● More complex use cases○ Message/event persistence○ At-least-once-delivery○ Message Replay

Page 9: Implementing Microservices with NATS
Page 10: Implementing Microservices with NATS

Aytra - Application Management Platform

Page 11: Implementing Microservices with NATS

Aytra - Background● Pivoted from a Cloud Management Platform● Monolithic Java app● Now has 20+ microservices written in Golang, Node-js and Java● Team with < 5 developers● Container based application● CI/CD pipeline for microservices

Page 12: Implementing Microservices with NATS

+

Page 13: Implementing Microservices with NATS

Aytra + NATS - Overview

Page 14: Implementing Microservices with NATS

● Different use cases○ Two services need to exchange data and NATS is replacing HTTP○ Event driven components○ Notification

● NATS proxies○ HTTP○ WebSocket○ Third party services

● Strategies○ Request/Reply with timeout pattern for microservices that need to exchange data

■ Avoid the callback hell○ NATS streaming for services that only publish data

Aytra + NATS

Page 15: Implementing Microservices with NATS

Aytra + NATS● Guidelines for subject names

○ Service name○ Version○ Resource info○ Param data

● GET /api/service/v1/resource/{id} -> service.v1.get.resource.*● Internal subjects

○ service.v1.priv.resource.internal.action

● Queue groups● Data format

○ JSON○ ProtoBuf?

Page 16: Implementing Microservices with NATS

Aytra + NATS - Tooling● Official NATS clients● NATS exporter for monitor● HTTP to NATS proxy● Distributed tracing?● Houston

Page 17: Implementing Microservices with NATS

Houston

Houston

Page 18: Implementing Microservices with NATS

Houston - Overview● What?

○ Helper built around the NATS official clients○ Provide boilerplates to wire microservices together

● Why○ Abstract the communication framework from the microservices

■ Easier to update■ Easier to create new microservices

○ Ensure all microservices implement the same messaging pattern■ Current support for Golang, Java and Nodejs

Page 19: Implementing Microservices with NATS

Houston - Examplefunc AuthMiddleware(p *Passenger, elem reflect.Value) (*houston.ErrorBody){

return nil}func LoggerMiddleware(p *Passenger, elem reflect.Value) (*houston.ErrorBody){

return nil}rocket := houston.Rocket{ Route: "service.v1.put.person.*", Params: houston.Params{{Index: 4, Name: "Id"},}, Group: "service", Middleware: houston.Middlewares{LoggerMiddleware, AuthMiddleware}, Callback: func(p *person) (*houston.ErrorBody) {

fmt.Printf("Trying to update person with id %d\n", p.Id)return nil

}}controlTower.Build(rocket)

● Middleware chaining● Parameter mapping● Error handling● HTTP like data model

Page 20: Implementing Microservices with NATS

Resources● Houston

○ Golang: https://bitbucket.org/aytra/houston-go

● NATS Streaming○ http://nats.io/documentation/streaming/nats-streaming-intro/

● NATS-HTTP Proxy○ https://github.com/sohlich/nats-proxy

● NATS exporter○ https://github.com/markuslindenberg/nats_exporter

Page 21: Implementing Microservices with NATS

Thank you

Page 22: Implementing Microservices with NATS

Questions?

diogogmt.com

@diogogmt