Schedule icon
Request icon
Script icon
Switch icon
Log icon
SlackIncomingWebhook icon

Upstash Serverless Redis Memory & Quota Sentinel

Audit Upstash Serverless Redis memory utilization against maxmemory thresholds on a schedule and alert via Slack before out-of-memory errors occur.

Categories
CloudInfrastructure

Upstash Serverless Redis is widely adopted across modern web applications, Next.js serverless functions, and microservices for low-latency session caching, rate limiting, and ephemeral key-value storage. Unlike self-hosted Redis clusters where memory ceilings are managed on dedicated virtual machines, serverless databases operate within strict plan-based memory tiers and daily request ceilings. When caches experience runaway key creation or unexpiring session accumulations, databases cross the maxmemory threshold, leading to sudden key evictions, performance degradation, or application-level OOM exceptions.

This blueprint implements an automated Day 2 operations sentinel for Upstash Serverless Redis. Operating on a periodic schedule, it directly inspects the Upstash REST API INFO memory telemetry, parses allocated bytes against plan ceilings, calculates real-time utilization percentages, and dispatches rich Slack alert cards with actionable remediation directives before production outages occur.

How it works

  1. Scheduled Invocation: The workflow runs on a periodic schedule (0 */4 * * *, shipped disabled for safe initial configuration) or on demand.
  2. Upstash REST Query: query_upstash_info executes an HTTP GET request to {{ inputs.upstash_endpoint }}/info/memory using io.kestra.plugin.core.http.Request, authenticating securely using the bearer token secret UPSTASH_REDIS_REST_TOKEN.
  3. Metric Extraction & Parsing: parse_memory_metrics runs inside an isolated python:3.11-slim container, parsing used_memory, maxmemory, used_memory_human, and maxmemory_human. It calculates the saturation ratio (used_memory / maxmemory) * 100 and determines operational status (CRITICAL vs HEALTHY).
  4. Operational Branching: evaluate_memory_saturation utilizes io.kestra.plugin.core.flow.Switch to evaluate the classified status:
    • When Healthy: Emits an audit log confirming normal memory headroom.
    • When Saturated: Invokes io.kestra.plugin.slack.notifications.SlackIncomingWebhook to dispatch a formatted alert card to #platform-alerts detailing current utilization, allocated memory, and suggested triage commands (SCAN + TTL).
  5. Telemetry Logging: log_audit_completion records the overall audit summary and key utilization metrics.
  6. Error Resilience: A dedicated errors handler catches HTTP connection timeouts or authentication failures, ensuring on-call teams are alerted if the health check itself cannot reach the database.

What you get

  • Automated OOM Prevention: Continuous inspection of Upstash memory allocation identifies runaway cache growth hours before eviction policies impact users.
  • Zero Infrastructure Footprint: Runs completely serverless using Kestra native tasks and containerized Python parsing, requiring no persistent monitoring agents.
  • Actionable Slack Alerts: Context-rich Slack messages direct SRE and platform engineers immediately to the offending database endpoint with concrete remediation directives.
  • Flexible Thresholds: Configurable percentage thresholds allow tailoring alerts to match development vs production reliability tiers.

Who it's for

  • Platform Engineers & Site Reliability Engineers (SREs) maintaining serverless data layers and serverless Redis infrastructure.
  • Backend & Full-Stack Developers operating Next.js or cloud-native applications backed by Upstash Redis.
  • Database Administrators (DBAs) tasked with monitoring cache memory health and capacity planning.

Why orchestrate this with Kestra

Building custom cron jobs or Lambda functions to poll Redis metrics introduces unmonitored scripts, scattered secrets, and brittle alert plumbing. Kestra provides:

  • Declarative YAML Orchestration: The entire monitoring and alert topology is codified in version-controlled YAML with transparent execution history.
  • Encrypted Secret Management: Upstash REST credentials and Slack incoming webhook URLs remain securely encrypted and masked in all execution logs.
  • Built-in Flow Logic: Native Switch branching and containerized Python scripts provide robust error recovery without external microservice dependencies.

Prerequisites

  • An active Upstash Redis database from console.upstash.com.
  • An incoming Slack webhook URL for operational alerting.

Secrets

Configure the following secrets in your Kestra namespace or instance settings:

Secret Name Description Example
UPSTASH_REDIS_REST_TOKEN Upstash Redis REST API authentication bearer token AX7rASQg...
SLACK_WEBHOOK Incoming webhook URL for destination Slack channel https://hooks.slack.com/services/T00/B00/X00

Quick start

  1. In Kestra, navigate to Flows and import this blueprint into your designated namespace (e.g., company.cache).
  2. Add your UPSTASH_REDIS_REST_TOKEN and SLACK_WEBHOOK into Settings > Secrets.
  3. Click Execute and provide your database's upstash_endpoint to test the audit pass.
  4. Review execution logs to verify memory parsing and ensure the Slack alert card renders properly.
  5. In the flow definition, toggle disabled: false on periodic_memory_audit to activate the automated 4-hour monitoring schedule.

How to extend

  • Automated Key Eviction Sweep: Chain a downstream task using io.kestra.plugin.scripts.python.Script to run SCAN and automatically delete expired or untagged temporary keys when memory exceeds 95%.
  • PagerDuty Integration: Add an io.kestra.plugin.pagerduty.Incident task within the CRITICAL branch to escalate persistent memory exhaustion to on-call engineers.
  • Multi-Database Fanout: Replace the single endpoint input with a io.kestra.plugin.core.flow.ForEach loop iterating over an array of Upstash database endpoints across regions.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.