Logo

dev-resources.site

for different kinds of informations.

Caching with Redis for Backend in Apache Superset

Published at
11/28/2024
Categories
elestio
redis
caching
superset
Author
kaiwalyakoparkar
Categories
4 categories in total
elestio
open
redis
open
caching
open
superset
open
Author
16 person written this
kaiwalyakoparkar
open
Caching with Redis for Backend in Apache Superset

Self-hosting Apache Superset and Redis on Elestio provides a foundation for creating interactive dashboards with optimized performance. One way to improve performance is by configuring Redis as the caching backend for Superset. This guide walks through the process of integrating Redis with Superset, highlights common pitfalls, and explains how to verify the setup to ensure everything is working as expected.

Why Use Redis as a Caching Backend?

Redis is a high-performance in-memory data structure store, often used as a database, cache, and message broker. In the context of Superset, Redis can significantly speed up dashboard queries by caching query results and reducing the load on your database. Moreover, Redis is also used for task scheduling and backend message handling when Celery is configured for Superset.

Hosting Superset and Redis on Elestio

Both Superset and Redis need to be set up on Elestio. Ensure that Redis is properly installed and running. You should have access to the Redis host, port, password, and optionally, database numbers for caching and Celery. Similarly, Superset should be up and running with its dependencies configured.

For Redis on Elestio:

  1. Log in to your Elestio dashboard and create a new Redis service.
  2. Note down the connection details (host, port, and password).

Caching with Redis for Backend in Apache Superset

Configuring Superset for Redis Caching

On your Elestio dashboard head over to the Tools section and access the VS Code there. We will be making all the required updates in the VS Code instance.

Caching with Redis for Backend in Apache Superset

Locate your Superset configuration file (commonly superset_config.py) under docker > pythonpath_dev and add Redis details for both caching and Celery task scheduling. In the file add the following code in the places shown like in the image.

Caching with Redis for Backend in Apache Superset

REDIS_PASSWORD = get_env_variable("REDIS_PASSWORD")
Enter fullscreen mode Exit fullscreen mode

Configure Celery

Celery enables task scheduling and background execution. Update the Celery configuration in superset_config.py:

broker_url = f"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/{REDIS_CELERY_DB}"

imports = ("superset.sql_lab",)

result_backend = f"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}/{REDIS_RESULTS_DB}"
Enter fullscreen mode Exit fullscreen mode

Configure Caching :

Use Redis for query caching by adding the following configuration to superset_config.py:

CACHE_CONFIG = {
    "CACHE_TYPE": "RedisCache",
    "CACHE_DEFAULT_TIMEOUT": 300,
    "CACHE_KEY_PREFIX": "superset_",
    "CACHE_REDIS_HOST": REDIS_HOST,
    "CACHE_REDIS_PORT": REDIS_PORT,
    "CACHE_REDIS_DB": REDIS_RESULTS_DB,
    "CACHE_REDIS_PASSWORD": REDIS_PASSWORD,
}
Enter fullscreen mode Exit fullscreen mode

Define Redis Environment Variables :

If you're using Docker, include the following environment variables in your .env file, these files are mounted in your docker-compose file. Be sure to make these changes in both the env files.

Caching with Redis for Backend in Apache Superset

After updating the configuration, restart your Superset services:

docker-compose down && docker-compose up -d

Enter fullscreen mode Exit fullscreen mode

Verifying Redis Connectivity

Check Superset Logs :

Access the Superset dashboard and find the View app logs under the Software section. Here you can see worker logs that state the success of the connection.

Caching with Redis for Backend in Apache Superset

Redis Insights :

Under the Redis service dashboard, you can access Redis Insights. Use the credentials provided to access the Redis Insights

Caching with Redis for Backend in Apache Superset

Once you are logged in, you can add your Redis Database by clicking on Add Redis Database and providing the details from the service dashboard. Here you will be able to see different statistics and usage to confirm the success of the connection.

Caching with Redis for Backend in Apache Superset

Debugging Common Issues

If you encounter issues such as "invalid username-password pair" or "authentication required," double-check the following:

  • Ensure the broker_url and result_backend in CeleryConfig are correctly formatted: redis://:<password>@<host>:<port>/<db>.
  • Verify that the Redis password is correct and that Redis is configured to allow password-protected access.

Thanks for reading ❤️

Integrating Redis as a caching backend in Apache Superset enhances the platform's responsiveness, especially for dashboards with heavy queries or frequent updates. By following this guide, you can ensure a seamless integration and enjoy the benefits of optimized performance in your analytics workflows.

Caching with Redis for Backend in Apache Superset

redis Article's
30 articles in total
Favicon
Protect Your APIs from Abuse with FastAPI and Redis
Favicon
Token Bucket Rate Limiter (Redis & Java)
Favicon
A Simple Guide to Connect to Amazon ElastiCache Redis from Outside of Amazon
Favicon
Caching in Node.js: Using Redis for Performance Boost
Favicon
How to Install and Run Redis Directly on macOS (Without Homebrew)
Favicon
Install Redis Locally in Windows
Favicon
Redis: Powering Real-Time Applications with Unmatched Performance
Favicon
Why does clustering with redis suck?
Favicon
Fixed Window Counter Rate Limiter (Redis & Java)
Favicon
Redis Data Structures
Favicon
Pub-sub Redis in Micronaut
Favicon
Real-Time Data Indexing: Powering Instant Insights and Scalable Querying
Favicon
How to Implement Caching in PHP and Which Caching Techniques Are Best for Performance?
Favicon
tnfy.link - One more shortener?
Favicon
Lettuce - A Java Redis Client
Favicon
Introducing keyv-upstash: Seamless Key-Value Storage for Serverless Redis
Favicon
Sherlock Holmes: The Case Of Redis Overload During a DDoS Attack
Favicon
Real-Time Location Tracking with Laravel and Pulsetracker's Redis Pub/Sub
Favicon
Redis Cache - A String story
Favicon
Working on Redis streams? Don't forget these commands.
Favicon
Caching with Redis for Backend in Apache Superset
Favicon
Redis Queue and Cron in Go
Favicon
Infinite redis request
Favicon
Rate limiting with Redis: An essential guide
Favicon
What do 200 electrocuted monks have to do with Redis 8, the fastest Redis ever?
Favicon
FLAIV-KING Weekly (Flink AI Vectors Kafka) for 18 Nov 2024
Favicon
Building a Real-Time Flask and Next.js Application with Redis, Socket.IO, and Docker Compose
Favicon
Spring Boot + Redis: A Beginner-Friendly Guide to Supercharging Your App’s Performance
Favicon
Boosting Speed and Performance with Advanced Caching in NestJS: How to Use AVL Trees and Redis
Favicon
I used GitHub as a CMS

Featured ones: