pg-api-0.1.0 is not a library.
pg-api
A high-performance PostgreSQL REST API driver built with Rust, featuring rate limiting, connection pooling, and comprehensive observability.
Features
- High Performance: Built with Rust and Axum for maximum throughput
- Connection Pooling: Efficient database connection management with deadpool-postgres
- Rate Limiting: Configurable per-account rate limits with sliding window algorithm
- Multi-tenancy: Support for multiple accounts with isolated configurations
- Observability: Built-in metrics, tracing, and optional OpenSearch integration
- Security: API token authentication, query timeouts, and audit logging
- License Management: Flexible offline/online license validation system
- Production Ready: SystemD integration, health checks, and graceful shutdown
Installation
From Source
# Clone the repository
# Build in release mode
# Run the binary
Using Cargo
Configuration
The API uses JSON configuration files located in the config/
directory:
Server Configuration (config/server.json
)
Account Configuration (config/accounts.json
)
API Usage
Authentication
All requests require an API token in the Authorization header:
Query Execution
Health Check
Account Information
Development
Prerequisites
- Rust 1.75 or higher
- PostgreSQL 12 or higher
- Optional: OpenSearch for observability
Running Tests
Running with Hot Reload
Linting
Formatting
Environment Variables
# Application
APP__ADDR=127.0.0.1:8580
APP__LOG_LEVEL=info
# PostgreSQL
PG__MAX_CONNECTIONS=100
PG__POOL_SIZE=25
# License (required for production)
LICENSE_KEY=your_license_key
# OpenSearch (optional)
OPENSEARCH_API_URL=https://opensearch.example.com
OPENSEARCH_API_TOKEN=your_token
OPENSEARCH_ENABLED=true
Architecture
┌─────────────────┐
│ HTTP Client │
└────────┬────────┘
│
┌────▼────┐
│ Axum │
│ Router │
└────┬────┘
│
┌────────▼────────┐
│ Middleware │
│ - Auth │
│ - Rate Limit │
│ - Metrics │
└────────┬────────┘
│
┌────▼────┐
│ Handler │
└────┬────┘
│
┌────────▼────────┐
│ Connection │
│ Pool │
└────────┬────────┘
│
┌────▼────┐
│PostgreSQL│
└─────────┘
Performance
Benchmark Results
Based on testing with standard hardware (8 CPU cores, 16GB RAM):
Metric | Value | Conditions |
---|---|---|
Throughput | 15,000+ req/s | Peak load with 1000 concurrent users |
Latency (p50) | 0.8ms | Simple SELECT queries |
Latency (p99) | 5ms | Simple SELECT queries |
Batch Processing | 100 queries in <50ms | Optimized batch endpoint |
JSON Serialization | 800K rows/s | 1KB payload per row |
Connection Pool | 99% efficiency | 100 connection pool |
Key Performance Features
- Sub-millisecond latency for simple queries
- 10,000+ requests/second on modest hardware
- Efficient connection pooling reduces database load
- Rate limiting prevents abuse and ensures fair usage
- Query batching for optimized throughput
Running Benchmarks
# Run performance benchmarks
# Run load tests
See docs/BENCHMARKS.md for detailed performance analysis.
Security
- API token authentication
- Per-query timeout enforcement
- SQL injection prevention through parameterized queries
- Audit logging for all database operations
- TLS/SSL support for encrypted connections
Contributing
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting merge requests.
License
This project is dual-licensed under MIT OR Apache-2.0. See LICENSE for details.
Support
For issues and feature requests, please use the GitLab issue tracker.
Acknowledgments
- Built with Axum web framework
- Uses deadpool-postgres for connection pooling
- Observability powered by OpenTelemetry