Testability in Microservices
This is from one of the few sessions, to be exactly two, that I found interesting from DeveloperWeek Austin 2018, I personally was expecting more, on the other hand, the 5-hour wait at Franklin BBQ was worth it.
Leaving that aside, this particular summary is regarding those aspects we need to factor in when testing Microservices, especially if one happens to be in the center of the storm, having decided to approach a problem using Microservices, before that though, what situation or challenge (besides being overly willing by mere excitement) warrants the use of Microservices:
The need to run asymmetrical workloads
How independent they are from one another and self-contained; something interesting that came out of the session prior to diving into the topic of testing, was the highligh of some design considerations.
Services should:
- Be a lightweight and discrete process.
- Run its own processes.
- Be individually deployable.
No, onto testing, What should be Test?
- Service Discovery
- Operational Overhead.
- Service interface versioning.
- Complexity that comes with Distributed Systems, such as: N/W Latency, Fault Tolerance, Serialization Overhead.
Approaches to Testing / Techniques
Orchestration
- Testing by invoking asynchronous processes and doing continuous monitoring.
- Use simulation to stabilize the dependencies and provide predictive behavior, Service Virtualization could be an option.
Service Virtualization
- We need to emulate a particular service or component that are acting dependencies.
- Useful when such dependnecy is being developed as well and not ready yet, the emulated version takes its place.
- Early testing.
A bit more on virtualization:
- Clients must be prepared for services to fail, this touches a little bit on resiliency and the discipline of CHAOS engineering.
- Emphasis on real-time monitoring of applications.
- Logging framework, this is of extreme importance for visibility, especially when we have decoupled systems.
Other practices such as correlating resources and application telemetry could also be taken into consideration.
Choreography
- Pushing messages into different event streams and picking them up elsewhere.
- Provide a variety of data to validate different event flows.
Testing best practices
Test Early using Service Virtualization
- Shift left with validation focus on unit and component testing.
- Overcome testing constraints by leveraging service virtualization.
Smart Endpoints and Dumb Pipes
- Integration testing to ensure decoupling between microservices.
- End to End testing to ensure Choroeography and Orchestration of components.
Infrastructure Automation
- Establish and drive validation at every step with CI/CD pipelines.
- Robust infrastructure automation strategy, Infrastructure as a Code it is worth looking into.
Decentralized Governance
- Contract testing to ensure things are Consumer driven and not Product driven.
- Ensure Services are fully functional as a standalone unit.
Design for Failure
- Validate performance, scalability & reliability early in your SDLC.
Descentralized Data Management
- Database isolation.
- Data Caching and Sharding.