Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 FastAPI Real-Time Data Processing API

High-performance asynchronous API built with FastAPI, featuring WebSocket support, Redis caching, and Prometheus monitoring.

✨ Features

  • Async/Await throughout for maximum performance
  • WebSocket support for real-time bidirectional communication
  • Redis caching with automatic expiration
  • Batch processing with concurrent execution
  • Server-Sent Events for data streaming
  • JWT authentication with role-based access
  • Prometheus metrics for monitoring
  • Docker Compose setup for easy deployment
  • 100% type hints for better IDE support
  • Comprehensive error handling

🏗️ Architecture

  • FastAPI - Modern async web framework
  • PostgreSQL + AsyncPG - Async database operations
  • Redis - Caching and pub/sub
  • Celery - Background task processing
  • Prometheus - Metrics and monitoring
  • Docker - Containerization

📊 Performance

  • Handles 10,000+ requests/second on single instance
  • Sub-100ms response time for cached requests
  • Automatic horizontal scaling support
  • Connection pooling for database and Redis

🚀 Quick Start

  1. Clone the repository
  2. Copy .env.example to .env
  3. Run with Docker Compose:
    docker-compose up
  4. Access API at http://localhost:8000
  5. View docs at http://localhost:8000/docs

📡 API Endpoints

Data Processing

  • POST /api/v1/data/process - Process single item
  • POST /api/v1/data/batch - Batch processing (up to 1000 items)
  • GET /api/v1/data/stream - Server-sent events stream

WebSocket

  • WS /api/v1/ws/{client_id} - Real-time bidirectional communication

Monitoring

  • GET /metrics - Prometheus metrics
  • GET /api/v1/health - Health check

💻 Local Development

# Install dependencies
pip install -r requirements.txt

# Run tests
pytest

# Start server
uvicorn app.main:app --reload

📈 Load Testing Results

Running 30s test @ http://localhost:8000/api/v1/data/process
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    38.42ms   12.31ms  203.44ms   89.23%
    Req/Sec   872.34    134.22     1.43k    71.83%
  312,453 requests in 30.10s, 43.82MB read
Requests/sec:  10,381.53
Transfer/sec:      1.46MB

🔒 Security

  • JWT token authentication
  • Rate limiting per user
  • Input validation with Pydantic
  • SQL injection protection
  • CORS configuration

📝 License

MIT

About

High-performance async FastAPI with WebSocket, Redis caching, and Prometheus monitoring

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages