Can someone explain how you would test Micro services?

Hi all

I keep hearing about Micro Services in interviews and at work in general.

And I wanted to ask anyone on here, what Micro Services are and how you would test it? I know the obvious answer would be to Google it but, the information doesnt feel consistent. And Iam just seeing loads of spider diagrams pictures, without any real explanations on whats going :frowning:

2 Likes

A microservice is a service that fits in your head.
If one can’t explain it fully, probably it does more than one thing, thus it can be broken down, thus it’s not a microservice. (Of course, other people can give whatever other definition)

how you would test it?

It depends on what you are investigating. One doesn’t ask a doctor how to “exam a patient”, but “how to exam a patient for XYZ conditions.”

In both cases, you will poke and exercise the investigation subject in some form, observing and experiencing its reaction.

1 Like

Microservice architecture means that you have (usually) a lot a small services and each of them is responsible for doing one thing, so a single microservice would be a relatively small piece of code.

I was (briefly) on a microservices based project, and we were considering using Contract testing for testing those microservices, there were around 30 of them at the time, probably many more now.

I was looking to an open source tool for contract testing called Pact, there’s a free course on TAU on it:

Also, I watched a lot of YouTube videos (mostly recorded conference talks) on testing microservices, so those might be helpful to you as well to see how others have approached this issue.

2 Likes

Testing microservices is very similar to testing services in general, i.e. you will have a contract (API) and some internal business logic and state and you test that logic and state using the contract by making requests to the service and observe the response.
One thing to note would be that if you have a fully monolithic system you do not need to care about integration between services, since you only have one. Where the more services you have the more integration points you have. Contract Testing is one technology that have popped up.
Another kind of problem that you can get is synchronization which means that changing and deleting stuff would rise on my importance list. The reason for the problem is that in monolithic system you commonly have one main database where everyone writes and read, so it is easier to make sure that every part of you system have the same data. With microservices you typically have plenty of databases. And some of your entities exists across multiple services. For example. Let’s say you have a user, the authentication service require your username and password. An authorization service require your username and access rights, a location service might have your address and geolocation, Then you maybe a shipping service that also have the address. And you want your data to be consistent on all these services.

Another perspective from a testing point of view is that it is typically easier to setup partial environments like running only a few of the services needed. Which speed up testing significantly, but you need to be mind full of your “production like qualities” that you care for and you have in that setup. So I found myself more testing on various different setups depending on the kinds of tests I was running (not working with service testing at the moment).

Some other topics to discover is testing in production / chaos monkey / agent testing etc. Which to some degree is a more holistic approach and is a very potent complement to the more exhaustive testing on a service level.

3 Likes

Thanks for the responses all. Is there a good example everyday example that we can use such as Google Map or Amazon just to help me break this down further and get a clearer picture?

But let me see if I can take a go at this.

If the Microservice architecture was to test Amazon’s online shop, it would have multiple API involved such as, the UI, shopping cart, inventory, accounts, algorithm for suggested product, etc, etc. Is this a good example of a mirco service architecture?
Dont know how much of a mess it would be if I said Amazon Prime???

1 Like

You’re definitely along the right lines with your model. Multiple micro services (ms) come together to allow a user complete actions.

For example sign in to a site, could include a Login UI ms which sends data to an authentication ms. That authentication ms could then call a user ms to get details etc.

If you want some more info on testing. I highly recommend Testing micro services by Martin fowler. Its helpes me alot. He has other posts on contract testing, consumer driven contract testing (pact is a tool for this) and lots more.

He’s one of my best oracles.

1 Like

Awesome thanks for that. I did see that article a while back and its pretty in depth.

It sounds like, theres always a mention of a “Gateway”. And I have seen some Microservices examples with or without the Gateway.
But from what I can understand, the responsibilities Gateway include but not limited to security and authentication.

So if there was a gateway involve, my setup would look something like this:

Web Browser >>>>

Mobile Devices>>>> API Gateway >>>>>>> Microservices

Is there any sort of Testing involved for the Gateway? Or is it just a means for traffic to pass through the backend services?