Flash: A Powerful Caching Library for NodeJsx

By — Manish Sharma (Platform Engineer)

UC Blogger
Urban Company – Engineering
4 min readApr 28, 2023

--

Introduction

At Urban Company, we strongly believe in the power of platforms. Our Microservices platform is our legacy and is one of the most stable platforms you will ever encounter.

As our business grew, we faced performance issues due to increased traffic. To solve this, we developed an Infra-agnostic platform with a powerful caching library called Flash, which enhances the user experience and makes caching effortless for developers.

Features of the Library

  • Ease of use — Just add the flash dependency in package.json, initialize the cache connection and make use of Caching functions as below:
import Flash from '@uc-engg/flash'

const Cache = new Flash();
Cache.connect(connectionConfig, serviceConfig, serviceName)
Cache.getData(…args) // get data from cache
Cache.setData(…args) // set data in cache
  • Monitoring and Logging — Out-of-the-box monitoring and logging for hit rate, miss rate, errors, total throughput, latency, etc. You just need to set the environment variable(LIBRARY_MONITORING_ENABLED) to true, and Flash will start producing metrics in a Prometheus consumable format.
export LIBRARY_MONITORING_ENABLED=true
{
"key_1": "event_name",
"key_1_value": "xp-service",
"key_2": "event_type",
"key_2_value": "getData",
"key_3": "info",
"key_3_value": "success",
"numkey_1": "response_time_ms",
"numkey_1_value": 104,
"numkey_2": "data_length",
"numkey_2_value": 36,
"log_type": "cache",
"message": "{\"service_name\":\"xp-service\",\"cache_key\":\"xp-service:xp-service:key1\"}"
}
  • Infrastructure Agnostic — We currently use Redis as a distributed cache store, but our microservices are agnostic of this underlying infra. In the future, it is possible to change it to some other caching solution with 0 code changes in the microservices. Recently, we migrated from a self-managed Redis cluster to an Elasticache cluster in a seamless manner for all microservices.
  • Bucketization — Bucket refers to a logical grouping of keys that simplifies operations and enables better monitoring of high throughput and space usage per bucket. Buckets can be configured to specify -
    1. Read/write access permissions enhancing data access control.
    2. Bucket-level TTL settings for better data lifecycle management.
"bucketA": {
"high_availability": true,
"default_ttl": 86400,
"registered_services": ["serviceA", "serviceB"]
},
"bucketB": {
"high_availability": true,
"default_ttl": 172800,
"registered_services": ["serviceC", "serviceD", "serviceE"]
}
Bucket-wise response times
  • Feature Adoption — As an organization scales, implementing new features and versions across all teams can be challenging. However, making changes to the library will automatically update all microservices without requiring intervention from service owners. Recently, we added JSON support for Redis in Flash and all the microservices were able to adopt it in a seamless manner.
   Cache.jsonSet(bucketName, "userKey", {f1: 5, f2: {a : 10}} , '$') 
Cache.jsonSet(bucketName, "userKey", {a: {c: 10}} , '$..f2')
Cache.jsonSet(bucketName, "userKey", '$..f2')
  • Versioning- Versioning reduces the impact of buggy code releases by providing developers adequate time to test newer versions by adopting it in a controlled manner i.e., service by service to start using new features.
"@uc-engg/flash": "1.0.1"

Impact

  • Earlier this year, we adopted Flash in a flow where we show top trending categories to our customers. It reduced the average response time from 200 ms to 100 ms.
Avg. Response time of show Top Trending API
  • We adopted Flash for our experimentation service, and it reduced the load on the underlying MongoDB cluster by 10X (3M => 250k rpm).
XP Service Throughput; Left (before caching), Right (after caching)

The team :

Manish Sharma is a driven and ambitious tech engineer who is constantly seeking new challenges to push the boundaries of what’s possible in the field of technology.

Sunish Dahiya is a results-driven tech engineer with a passion for solving complex technical challenges.

Karan Bansal is an engineering leader with a passion for all things tech. He excels at collaborating with cross-functional teams to deliver scalable solutions that drive business success.

Kushal Singh has a proven track record of delivering top-quality software solutions that exceed expectations and is always eager to take on the next big thing in tech.

Sounds like fun?
If you enjoyed this blog post, please clap 👏(as many times as you like) and follow us (@UC Blogger). Help us build a community by sharing on your favorite social networks (Twitter, LinkedIn, Facebook, etc.).

You can read more about us in our publications —
https://medium.com/uc-design
https://medium.com/uc-engineering
https://medium.com/uc-culture

If you are interested in finding out about opportunities, visit us at http://careers.urbancompany.com

--

--

UC Blogger
Urban Company – Engineering

The author of stories from inside Urban Company (owner of Engineering, Design & Culture blogs)