Skip to content

sofyan-solutions/query-shield

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Query Shield

💫 High-performance database proxy built with Rust to prevent expensive database upgrades.

Overview

Query Shield is a sidecar proxy that sits between your application and database, implementing intelligent query optimization to reduce database load and prevent costly upgrades.

Key Features

  • Query Deduplication: If 100 requests arrive within 10ms with the same query, the proxy sends only 1 query to the DB, sharing the result with others (prevents Thundering Herd).
  • Rate Limiting per Query: Blocks "garbage" queries that spike database CPU to 100%.
  • Slow Query Monitoring: Identifies and logs performance bottlenecks with detailed statistics and query pattern tracking.
  • Connection Pooling: Efficient connection management using Rust's async runtime.

Quick Start (with Docker)

The easiest way to run Query Shield is using Docker. We provide pre-built images on Docker Hub.

# 1. Pull the latest image
docker pull sofyan-solutions/query-shield:latest

# 2. Setup your configuration
# Copy the example config and customize it
cp config/config.example.toml config/config.toml

# 3. Run with Docker Compose
docker-compose -f docker-compose.prod.yml up -d

Real-World Testing (Sample App)

To validate Query Shield with a realistic workload, you can use our Sample App. This setup starts the proxy, a MySQL database, and a Go-based application that implements dual-connection strategy (reads via proxy, writes direct).

# Start the full stack (Proxy + Sample App + MySQL)
docker-compose -f docker-compose.sample-app.yml up -d

# Check sample app health
curl http://localhost:18080/health

Configuration

Query Shield can be configured via config/config.toml. Key features like deduplication, rate limiting, and monitoring can be toggled and tuned there.

Slow Query Monitoring

To enable performance monitoring, update your config.toml:

[query_monitoring]
enabled = true
slow_query_threshold_ms = 100      # Log queries slower than 100ms
statistics_window_seconds = 3600   # Keep stats for the last hour
enable_query_pattern_tracking = true

The proxy will periodically log structured JSON summaries of query performance to the tracing logs.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages