DevoxxFR 2024 Reproducible Builds with Apache Maven
Microservices Go kit Build Services
1. Microservices in Go with Go kit
Shiju Varghese
https://medium.com/@shijuvar
DevConf.IN
August 02, 2019
Bengaluru
2. About Me
• Consulting Solutions Architect on Go and Distributed Systems
• Published Author: Web Development with Go and Go Recipes
• Awarded Microsoft MVP seven times
• Speaker at numerous conferences
• medium.com/@shijuvar | github.com/shijuvar | linkedin.com/in/shijuvar
3. Agenda
• Introduction to Microservices Architecture
• Introduction to Go kit
• Building Microservices with Go kit
6. Microservices is an architectural style for building
highly scalable applications, in which an application
decomposes into a set of services as functional
components.
Microservices Architecture is all about functional
decomposition.
7. • A modern, practical programming language
• Concurrent, Simple, Fast, Type-safe, Compiled very quickly
• A great language for Cloud-Native, Microservices
Go Programming Language
9. Go kit
• A programming toolkit (collection of Go packages) for building
robust, reliable, maintainable microservices
• Solves common problems in distributed systems
• Bootstrap development towards Microservices
• Go kit design is well-suited for modern software design: both
microservices and elegant monoliths
10. Go kit Architecture
There are three major components in the Go kit based application
architecture:
• Transport layer: The transport domain
• Endpoint layer: An RPC method
• Service layer: Business logic layer
11. Transports
• The transport domain is bound to concrete transports
• Provide transports like HTTP, gRPC, NATS, AMQP, Thrift, etc
• A single microservice can support multiple transports
12. Endpoints
• An RPC method bound to a service method
• RPC as the primary messaging pattern
• Each endpoint exposes the service method to the outside world using
Transport layer
type Endpoint func(ctx context.Context, request interface{}) (response
interface{}, err error)
13. Services
• Business logic modelled as interfaces
• Based on the Clean Architecture or the Hexagonal Architecture
• No knowledge about endpoint, concrete transports and encoding/
decoding
14. Clean Architecture
The central rule of The Clean Architecture is
the Dependency Rule, which says:
Source code dependencies can only point inwards.
In other words, the source code of each circle can
only access code in an inner circle but never any
code in an outer circle.
15. Flow of requests and responses
• Request flow: Transport layer -> Endpoint layer -> Service layer
• Response flow: Service layer -> Endpoint layer -> Transport layer
17. Middleware
• A strict separation of concerns through use of the decorator
• Wrap endpoints or services to add functionality, such as logging, rate
limiting and distributed tracing
• Two types of middlewares: Endpoint middleware and Service middleware
18. Endpoint Middleware
• An endpoint middleware is a function that takes an endpoint and returns
an endpoint.
type Middleware func(Endpoint) Endpoint
• Use endpoint middlewares for transport-domain concerns, like circuit
breaking and rate limiting.
19.
20. Service Middleware
• An service middleware is a function that takes a service and returns a
service.
type Middleware func(Service) Service
• Use service middlewares for business-domain concerns, like logging and
instrumentation.
23. Design of Go kit services
1. Implements the core business logic by defining
an interface for service and providing a concrete
implementation.
2. Writes service middlewares to provide additional
functionality, like logging, analytics,
instrumentation — anything that needs
knowledge of business domain.
3. Go kit provides endpoint and transport domain
middlewares, for functionality like rate limiting,
circuit breaking, load balancing, and distributed
tracing — all of which are generally agnostic to
business domain.