March 22, 2023

Speed Up your Applications by Caching at the Edge with HarperDB

Welcome to Community Posts
Click below to read the full article.
Summary of What to Expect
Table of Contents

In this article, we’re going to discuss caching at the edge. We'll create a simple caching project with HarperDB to cache the result of an API call, and compare the speed of an un-cached api route vs. a cached api route.

You'll see that caching the result of an api request will speed up subsequent requests, and also make it less likely that our app gets rate limited.

  1. Understand caching: Caching is a technique to save data or web pages for quick access in the future, reducing the need for repetitive processing or fetching from a database.
  2. Introduction to caching at the edge: Learn about "caching at the edge," a modern technique that brings computation and data storage closer to the data source, improving response times and reducing bandwidth.
  3. Introducing HarperDB: HarperDB is a distributed application and database platform that enables low-latency access to datasets and applications by distributing them globally.
  4. Edge computing and CDNs: Explore the concept of edge computing, which brings the server closer to the user, and content delivery networks (CDNs), which cache static files worldwide.
  5. Why HarperDB is suitable for caching: HarperDB's distributed architecture reduces latency by placing the application and data closer to the end user, making it an ideal choice for edge caching.
  6. Installing and setting up HarperDB: Install HarperDB locally and set up HarperDB Studio to connect to your local instance.
  7. Creating a caching project with HarperDB: Create a schema and table in HarperDB to store cached data.
  8. Setting up a custom function project: Create a custom functions project in HarperDB Studio to define custom routes that interact with the HarperDB database.
  9. Creating an un-cached route: Implement a route that fetches a post from an external API on each request, without caching.
  10. Creating a cached route: Develop a route that checks if a post is cached in HarperDB and returns it if found. If not cached, fetch the post from the API, cache it in HarperDB, and return it.
  11. Testing the routes: Use tools like Postman to test the un-cached and cached routes, observing the difference in response times.
  12. Improving caching strategy: Discuss the possibility of adding an expiry date to cached data to ensure the cache remains up to date.
  13. Conclusion: HarperDB's edge caching capabilities can significantly improve application speed and reduce latency by distributing data and application logic closer to the user.