Azure API Management – smart proxy for your API

I. Overview Azure API Management (API Management) is a great managed service provided by Microsoft. You can use API Management for API-s hosted in Microsoft Azure, any public cloud or even on-premise.

API Management is proxy sitting in front your API that offers various useful features such as:

  1. API documentation and an interactive console
  2. Throttle, rate limit and quota your APIs
  3. Monitor the health of your APIs and quickly identify errors
  4. Bring modern formats like JSON and REST to existing APIs
  5. Consolidate multiple backends into a single endpoint
  6. Gain analytic insights on how your APIs are being used
  7. Global caching layer
  8. Standard workflow for managing access to you API-s
  9. Validation and modification of requests / responses
  10. Logic operation exposed via policies

II. Context As you can see API Management can be useful in various scenarios but today we will focus on one aspect of the caching abilities. One of the most important Azure Architecture patterns is Cash Aside pattern Cache-Aside Pattern The workflow is as follows:

  1. Mobile client (or any type of web client) makes a request to an API
  2. The API accesses the cache and checks if the data is already there, if so we go directly to 5 (return the data to the client)
  3. We have a cache miss (data is not is present in the cache), so we retrieve it from the data store
  4. The API saves the data in the cache so until it is expired every new request will be served by the cache
  5. The data is returned to the client

This pattern is very typical and used broadly. So one application of this pattern is the following: Mobile Service application Here the API is acting as reverse proxy for Mobile App reducing the load with the help of Redis cache. One reason for that solution could be that the Mobile App is written in node.js and we have .Net team that needs to manage it. Another way of utilizing cache is to use Redis directly from the Mobile App as shown below: Mobile App with Redis III. Optimization However, we can simplify the scenario by adding API Management in front Mobile App  and define cache on read operations. API Management integrated In this case we don’t need to have dedicated Redis cache and also we don’t have to make explicit checks if a request can be served by the cache or by the original data source. Every request made to the API Management will be evaluated and if we have it in the cache we will not go to the Mobile App. And in case of cache miss we will go once to the Mobile App for the cache expiration period. In this scenario the Mobile App is not concerned about the caching layer. This simplifies the code and infrastructure we need to manage and it is matter only of configuration. The proposed solution is very useful if:

  1. You already using API Management in Standard or Premium tier
  2. Your cache size requirements are not that high
  3. You want to reduce the complexity of your code and infrastructure
  4. You have global caching requirements

The proposed solution is very appealing in cases you need to offer global caching that we will explore in following posts. In later posts we will also show how we can use policies to verify the request and modify the response. IV. Summary API Management offers very easy way to add caching layer to your API-s without adding additional Redis cache instances.  Depending on your scenario API Management can significantly simplify your architecture. Thank you for your time! Kanio

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s