Building APIs is all fun and games until you run into performance issues.
And then suddenly no one wants to use your APIs.
The only way out is to improve the performance of your APIs to an acceptable level.
Here are 5 strategies that can help you out.
1 - Caching
The idea of caching is simple.
Store frequently accessed data in a cache so that you can access it faster when needed.
If there’s a cache miss, fetch the data from the database.
Caching is quite an effective strategy with quick results but cache invalidation and deciding on the caching strategy can be challenging.
You can steal some ideas from big companies that are solving these challenges and sharing their findings. We have covered a few of them earlier.
2 - Scale out with Load Balancing
If one server instance isn’t enough, you can think of scaling your API to multiple instances.
So - where’s the catch?
You need to find a way to distribute requests between these multiple instances.
This is where the Load Balancer steps in.
It not only helps with performance but also makes your application more reliable.
However, load balancers work best when your application is stateless and easy to scale horizontally.
If interested, you can check out my detailed post on Load Balancers.
3 - Async Processing
Sometimes, you can’t solve multiple problems together.
The best way is to park them for later.
With async processing, you can let the clients know that their requests are registered and under process.
Then, you process the requests one by one and communicate the results to the client later on.
This allows your application server to take a breather and give its best performance.
But of course, async processing may not be possible for every requirement.
4 - Pagination
If your API returns a large number of records, you need to explore Pagination.
With pagination, you limit the number of records per request, thereby reducing the amount of data transferred over the network.
This improves the response time of your API from the client’s perspective.
5 - Connection Pooling
An API application often needs to connect to the database to fetch some data.
Creating a new connection for each request can degrade performance.
It’s a good idea to use connection pooling to set up a pool of database connections that can be reused across requests.
This is a subtle aspect but in highly concurrent systems, connection pooling can have a dramatic impact on performance.
👉 So - what other strategies have you used to boost the performance of your APIs?
My Thoughts on AI Tools like Devin
I recently shared my views on LinkedIn and X (Twitter) about how you should think as a software engineer about AI tools like Devin.
Here’s what I wrote:
Your competition is not with Devin.
Your competition is with the software developer who spends every single day learning new stuff, building projects, and getting better at the craft.
Imagine what's going to happen once that developer gets access to Devin or any other tool for that matter.
The post created quite a bit of conversation on both of the platforms and some really interesting points were made.
If you’ve also been thinking about this topic, it might be worthwhile to check out the posts. Here are the links:
Also, you can share your views on the topic over here.
Shoutout
A few interesting articles I read this week:
From Tech Lead to Team Lead by
: A real-life experience about moving into a Team Lead role.The Devin Debate: Engineering Evolution or Hype by
: An interesting take on the whole situation around Devin and what it could mean for software engineers.- : An interesting post about how a developer can approach building side projects.
That’s it for today! ☀️
Enjoyed this issue of the newsletter?
Share with your friends and colleagues.
See you later with another value-packed edition — Saurabh.
Caching takes it all! Excellent summary my friend, keep them coming!
+1 for the take of Devin. Focus on becoming a better developer day by day, then the things will be fine.