Testable Integration Architecture
Testable Integration Architecture
Written by Tom Keeber , Principal Software Engineer
Hang around me long enough and I’ll probably start recommending books.
One of my favourites is?Enterprise Integration Patterns . Although this book is now close to 20 years old and contains scary words like “Enterprise” its still extremely relevant and the patterns it describes are a foundation for message based asynchronous systems.
Near the beginning of that book there is a great quote.
Change is inevitable
Change is inevitable you say? Well, at Dunelm we want to be able to move safely at speed. Which means we invest in our automated testing framework. Why do we do this? Because we want to make changes quickly and safely and if something is broken we want that feedback quickly.
In this blog post I’m going to talk about how the different architectural integration choices you make affect your ability to make changes (the extensible architecture side) and make them safely (the testing part).
Note; I’m aware that there are far more factors to be considered when creating software — I’m going to use the usual blog post get out clause — that they are out of the scope of this article.
There are 4 “Architectural Styles” for passing data between different systems defined in Enterprise Integration Patterns.
Each of these integration options comes with their different challenges when it comes to testing. Lets talk through each…
File Transfer
If you’ve been in software long enough sooner or later you’ll be passing data around using File Transfer. Someone writes a file and someone reads it.
You often see File Transfer integration used for large data sets or where documents must be supplied in a pre-determined format.
Unfortunately, you also see File Transfer integration used where other integration mechanisms would do a much better job. This is usually older, 3rd party systems.
The big advantage here is the loose coupling between different systems. The Producer (creator of the file) and Consumer (reader of the file) could be written in entirely different frameworks/languages.
As with all integrations there needs to be a shared agreement on the format of the file.
Testing File Transfer Integration
File Transfer integration can be hard to test due to a lack of visibility, complexity, environment variability, and security concerns. You may also be limited in your automation due to certain file types. It is the lack of visibility and feedback that can hamper the benefits of automated testing — particularly if anything changes in file format by either the consumer or producer.
The file transfer mechanism acts as a natural testing barrier. For the outbound testing, where you are creating or updating a file, an automated test that creates a file and validates its format would a natural happy path integration test.
Where automation testing becomes tricky is the End-to-end journey and error scenarios. As this type of integration depends so much on the underlying File system — network connectivity, server capacity, and other environmental variables are very tricky to automate the testing of.
Advantages
Disadvantages
Shared Database
One database or schema is shared amongst multiple systems.
Fast becoming one of my least favourite integration types and a massive anti-pattern in a microservice domain driven architecture.
The big advantage of this type of integration is the ability to share the data amongst systems and know that data is from a single source of truth.
But it does come with some big challenges. One of the big ones will be how you manage database connections and load on your database (read/write replicas and other strategies will help with this). The other, and the one that really effects testing, is the ability to understand how schema and data changes effect all the systems talking to the database. If any system can make a schema change to the database, then you have a big problem in ensuring integrity.
Shared Database Integration Testing
Unlike File Transfer integration — Shared database integration requires you to think about feedback you get from changes in a different way. If any system can modify the schema or data anywhere in the database then you will run into problems which may not be easily identified — until it breaks.
When using this pattern, follow these guidelines to make sure that you have observability of integrated systems and get feedback on data and DDL changes;
Advantages
领英推荐
Disadvantages
Remote Procedure Invocation
Remote Procedure Invocation?applies the principle of encapsulation to integrating applications.
This is where I think the Enterprise Integration Patterns book needs an update.
Instead of RPI — I think a more modern description would be?API based integration. The idea is that we introduce loose coupling between systems and data by providing a predefined way of performing operations on or retrieving that data.
There are number of different implementations this some older ones such as Java RMI and some more recent such as Google created?gRPC . Probably the most popular is one you will know well — Web Services or REST based services usually over HTTP.
This integration style covers a huge and popular area of integration between systems and has some major advantages — ease of use, lots of implementation options with popular and well defined standards.
One of the big disadvantages is the use of networking and HTTP can introduce unexpected failures that often need to be handled by the client.
So what does this mean for testing.
Well, if well designed we can think of our web service as black box. We shouldn’t need to understand the details of what the services is doing, but only the effects of that action.
At a high level its important that we design our services in such a way that;
This can lead to a simple testing strategy. But it is often not enough particularly in large complex systems.
At Dunelm we use a lot of REST based micro services for us this means ideally each service should;
Advantages
Disadvantages
Messaging
Asynchronous communication solves so many problems in a complex distributed system. But also adds a huge amount of complexity to our systems particularly around testing.
Again it comes down to feedback — in a Asynchronous system — how long do you wait for something NOT to happen? and how do I get feedback that something?has?happened?
You need to decide on a few different strategies on how you are going to test.
Couple of practicals on this;
Advantages
Disadvantages
Conclusion
An architecture that restricts automated testing will restrict business agility and ultimately lead to decrease in productivity.
If your goal is to create a system that is flexible and building for velocity, then choosing your integration option will massively effect your testing strategy and the cost of automated testing.
If we make the wrong choices with our integration architecture testing will be harder. The boundaries around our tests can become blurred, testing loops and feedback can become harder to determine.