Transcript
Implementing Microservices with NATS
Agenda● Microservices● NATS● Aytra● Aytra + NATS● Houston
Microservices
Microservices
Microservices - What?● Micro benefits
○ Flexibility○ Availability○ Security
● Monolithic benefit○ speed?
● Micro challenge○ message passing
Microservices - Why?● Scale application components independently● Roll out features or experiments more freely● Faster iteration● Be aware of challenges
○ API interfaces○ Communication○ Latency○ Tooling
NATS
NATS
NATS - What?● The glue for your microservices● Cloud-native messaging platform● Highly performant● Extremely lightweight● Very flexible
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
Aytra - Application Management Platform
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
+
Aytra + NATS - Overview
● 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
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?
Aytra + NATS - Tooling● Official NATS clients● NATS exporter for monitor● HTTP to NATS proxy● Distributed tracing?● Houston
Houston
Houston
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
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
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
Thank you
Questions?
diogogmt.com
@diogogmt
top related