Improve Azure API Management performance by 10x through Caching
Abs07act
I have written this in many of my Azure API Management
blog posts that API Management will become very mission critical in your Azure
Cloud Architecture and s07ategy. And customer after customer this continues to
be proved. Any component of Enterprise wide Architecture becoming critical
means it will also give birth to critical problems and test your architecture
skills in all respect.
I have seen this repetitive pattern at customer who has
embarked on journey of Azure API Management that, performance issues are
inevitable after certain massive load and you need to tweak Azure API
Management to continue to serve at optimum level. By far, in the history of web
application Caching mechanisms gives you awesome performance boosts. Same is
07ue with Azure API Management and I will explore the same in this blog post.
Let’s go!
When we say “caching in API Management” then essentially
we are talking about caching the RESPONSE of backend API inside the storage
[not Azure Storage] of Azure API Management. You always and always cache only
GET methods.
Warning - Technically you can cache
POST methods also, but not recommended. I would call it a hack. PUT and DELETE
methods are never to be cached.
Get method caching is the recommended approach of
caching API response. If you use Azure API Management then Azure API Management
acts as a middle ware and provides caching facility for all backed APIS hence
saving you from cache implementation from all of the individual backend APIs.
Refer to below diagram –
When users requests the API Management for some data
using REST API GET method for the first time, then the response is sent by
backend API. This response is cached in API Management inbuilt storage and also
passed onto to user. The next time when user calls the same method, the cached
response is sent back, without actually sending the query/ request to backend
APIs; till the time to live is not elapsed. This results in saving of round 07ip
to backend API and hence the response to user is delivered at lightning fast
speed. Resulting into overall performance improvement of APIs responses and
latency.
In Azure API Management, when you add an API, you have
API at high level and it contains the operations. Then an API can also belong
to multiple Products. An individua API operation can never exists in Products independently.
The caching in API Management is configured using Policies. So in essence caching
can be implemented at below levels in Azure API Management – as per below diagram
–
Note – If your API contains
an operations of mix Http methods then you will have to configure the Caching policy
in Azure API Management “at individual level of operation in APIs”. This can become
a bottleneck or hectic work to manage the policy configuration of APIs at every
operation level.
Therefore as a best practice you can either have APIs
designed to contain only GET methods and for rest of the methods define new APIs.
Then add GET methods based APIs in Products and define the caching policy in
Azure API Management at product level. This simplifies the design of your APIs
in Azure API Management a lot and implementation of caching becomes super easy.