Design patterns for microservice architecture x
whoami • Lead Software Developer
 @ The Software House • adiqpl @ twitter • adrian@zmenda.com • linkedin.com/in/adrianzmenda Adrian Zmenda
What we’ll cover today • Basics • Communication • Internal Communication • Security • Availability • Configuration • Logging
Should I use microservices?
What is a microservice? • Loosely coupled • Independently deployable • Highly maintainable and testable • Organized around business capabilities • Owned by a small team
When microservices are good idea • Complex application • High scalability • Rapid and frequent delivery
Drawbacks • running distributed system is hard • maintaining consistency is challenging • ops complexity is high
Should I start with microservices?
Monolith
Monolith source: CBS
source: Simon Brown
Modular Monolith source: Simon Brown
Can we go even further?
Self-Contained System source: Roman Stranghöner
Self-Contained System sooo, it’s like microservices. right?
Communication
Direct
Gateway
Backend For Frontend
Internal Communication
Remote Procedure Invocation • Synchronous • Simple • Easy to understand • Follows Request / (Response)
REST • Familiar • Based on HTTP • No intermediate broker source: nginx
Apache Thrift • Backed by Facebook • Language neutral contract-file • Code generation • Support for notifications
• Backed by Google • Calls visible as internal • Code generation • Simple contracts (Protocol Buffers)
Message Broker • Asynchronous • Follows Publish / Subscribe • Increases complexity source: nginx
Message Broker
Combined Messaging source: nginx
Security
No ACL • Simple • Rarely possible • No additional over-head
ACL in every microservice • Duplication of ACL logic • Redistributes ACL across all microservices • Contexts mixing
ACL as dependent microservice • ACL defined as single microservice • Prevents duplication and redistribution • Could be a Single Point of Failure
ACL on Gateway • ACL on Gateway (could be implemented as microservice) • No duplicated ACL code in microservices • No huge over-head, simplifies internal communication
Availability
?
? DNS
? Load Balancer (router)
Service Discovery
Client-Side Service Discovery
Server-Side Service Discovery
Service Registries
Self-Registration
3rd Party Registration
Consul • Service Registry • Healthchecking • Key/Value Storage • Secure Communication • Multi Datacenter
Handle Failures • Define network timeouts • Limit no. of outstanding requests • Provide fallbacks
Circuit Braker
Configuration
Externalized Configuration {    "sectionA":{       "valueA":"ABC123",       "valueB":"XYZ321"    } }
One configuration to rule them all {    "sectionA":{       "valueA":"ABC123",       "valueB":"XYZ321"    },    "sectionB":{       "valueC":"ABC123",       "valueD":"XYZ321"    } }
One configuration to rule them all {    "sectionA":{       "valueA":"ABC123",       "valueB":"XYZ321"    },    "sectionB":{       "valueC":"ABC123",       "valueD":"XYZ321"    } } {    "sectionA":{       "valueA":"ABC123",       "valueB":"XYZ321"    } }
Logging( ) Tracing
How to debug microservices? • Aggregate all logs in one place • Track Exceptions • Trace requests • Visualize
Measure • Monitor relevant platform details: • execution time of db queries; • request execution time; • number of request per minute; • response times; • success/failure ratio; • resources usage
Prometheus
Grafana
Now, we can do microservices the right way
Can we do them fast?
Define standards / contracts
Embrace tooling
Example: Service structure generation
Example: GRPC code generation
Example: GRPC code generation
How to organize microservices in code repositories?
Multi-repository • Pros: • better owner (team) separation; • clear scope • Cons: • hard to keep consistency (versioning is complex); • risk of becoming a monolith; • introduces more CI/CD setup costs
Mono-repository • Pros: • easy to maintain consistency; • easier versioning • Cons: • different teams may affect each other; • might lead to tight coupling; • longer build times
• Databases • Testing • CI / CD as essential tool • Destructive Testing • Deployments • many, many more… What we didn’t covered today youtu.be/D8l19VEokBA
Summary • think twice if you really need a microservice architecture • ensure you have all necessary resources to operate distributed systems • make cold and educated decisions what’s best for your case, not netflix • embrace contracts and tooling
Resources • microservices.io • martinfowler.com/microservices • scs-architecture.org • codingthearchitecture.com • nginx.com/blog/introduction-to-microservices
Don’t miss our upcoming webinars! Sign up for our newsletter! ✍ tsh.io/newsletter
Thanks 😉 tsh.io

Design patterns for microservice architecture