Design a micro-service that would use (wrap, really) any of the 3rd party location-from-IP address service. The service that you’ll build must expose a REST interface.
- Service should maintain a cache
- Service should maintain a persistent store of the looked-up values
- Unit tests
- Integration tests
- It may use Swagger (or Postman) as a UI.
- Clone the repo
- Run
docker compose up --detached
to start the service - Navigate to http://localhost:5000/swagger
- Use the swagger UI to test the service
- Uses an in memory cache. If it was scaled out, could move to a distributed cache
- Doesn't store IP locations when the lookup was not found by the third party. The IP address could be allocated at a later date
- Uses MongoDB as it's simple to get up and running, and has Docker support
- A unique index on the IP address is added using a hosted service on start up. This should ideally be done by a migrations tool so that the application user doesn't need elevated privileges
- These are focused around the cache behaviour as this is difficult to test in an integration test
- I likely wouldn't use Moq in the real world and would connect to a MongoDB instance. Moq was used here for simplicity
- These are focused around the vertical slice of getting an IP location
- We verify that IP v4 and v6 can be looked up
- We verify that an invalid IP returns a 400
- We verify that when an IP isn't found it returns a 404
- We verify that an IP that is found is returned as we expect
- We verify that an IP that is found is stored as we expect in MongoDB