{"id":26562575,"url":"https://github.com/zvdy/api-performance","last_synced_at":"2026-04-08T18:02:25.166Z","repository":{"id":282963972,"uuid":"950235335","full_name":"zvdy/api-performance","owner":"zvdy","description":"A comprehensive demonstration of 7 proven API optimization techniques implemented in FastAPI, with benchmarking tools to measure and compare performance improvements.","archived":false,"fork":false,"pushed_at":"2025-08-18T01:15:12.000Z","size":182,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-03T08:48:34.088Z","etag":null,"topics":["api","api-optimization","caching","compression","docker","fastapi","microservices","postgresql","python","redis","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zvdy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-17T21:01:36.000Z","updated_at":"2025-03-18T14:14:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"a30ac082-50bd-48fb-b8ed-a72e26f2a113","html_url":"https://github.com/zvdy/api-performance","commit_stats":null,"previous_names":["zvdy/api-performance"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zvdy/api-performance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2Fapi-performance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2Fapi-performance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2Fapi-performance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2Fapi-performance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zvdy","download_url":"https://codeload.github.com/zvdy/api-performance/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zvdy%2Fapi-performance/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31567227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-optimization","caching","compression","docker","fastapi","microservices","postgresql","python","redis","rest-api"],"created_at":"2025-03-22T15:18:09.986Z","updated_at":"2026-04-08T18:02:25.158Z","avatar_url":"https://github.com/zvdy.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API Performance Optimization Techniques\n\nThis repository demonstrates 7 proven techniques to optimize API performance, offering concrete implementations, comprehensive benchmarks, and practical insights for production applications.\n\n## Project Structure\n\n```\n.\n├── api/                    # Main API service\n│   ├── routes/            # API route handlers\n│   ├── techniques/        # Optimization implementations\n│   ├── app.py            # FastAPI application\n│   ├── models.py         # SQLAlchemy models\n│   └── requirements.txt   # API dependencies\n├── benchmarks/            # Benchmarking suite\n│   ├── data/             # Sample data for tests\n│   ├── techniques/       # Individual benchmark implementations\n│   ├── requirements.txt  # Benchmark dependencies\n│   └── run.py           # Benchmark runner\n├── databases/            # Database configurations\n│   ├── postgres/        # PostgreSQL init scripts\n│   └── redis/           # Redis configuration\n└── docker-compose.yml    # Service orchestration\n```\n\n## Optimization Techniques\n\n| Technique | Description | Average Improvement |\n|-----------|-------------|-------------------|\n| Connection Pooling | Reuse database connections | ~113x faster |\n| Caching | Redis-based data caching | ~20x faster |\n| Pagination | Efficient data chunking | ~2.6x faster |\n| Async Logging | Non-blocking logging | ~1.4x faster |\n| N+1 Query Prevention | Optimized query patterns | ~1.5x faster |\n| Compression | Response payload reduction | ~1.1x faster |\n| JSON Serialization | Optimized data transformation | Stable baseline |\n\n## Quick Start\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/zvdy/api-performance.git\n   cd api-performance\n   ```\n\n2. Start the services:\n   ```bash\n   docker-compose up -d\n   ```\n\n3. Run benchmarks:\n   ```bash\n   # Run all benchmarks\n   python benchmarks/run.py\n\n   # Run specific benchmark\n   python benchmarks/run.py --technique compression --iterations 10 --concurrency 10\n   ```\n\n## Benchmarking\n\nThe project includes a comprehensive benchmarking suite that measures:\n- Response time (ms)\n- Requests per second\n- Improvement factor vs baseline\n- Technique-specific metrics (e.g., compression ratio)\n\nExample benchmark command:\n```bash\npython benchmarks/run.py --technique compression --iterations 10 --concurrency 10\n```\n\nParameters:\n- `--technique`: Specific technique to benchmark (optional)\n- `--iterations`: Number of test iterations (default: 3)\n- `--concurrency`: Number of concurrent requests (default: 10)\n- `--output-dir`: Custom output directory (optional)\n\nResults are saved in the `reports/` directory with timestamps.\n\n## Implementation Details\n\n### 1. Connection Pooling\n- Configurable connection pool size\n- Connection health monitoring\n- Automatic connection recycling\n- AsyncSession support with SQLAlchemy\n\n### 2. Caching\n- Redis-based LRU caching\n- Configurable TTL\n- Automatic cache invalidation\n- Circuit breaker pattern\n\n### 3. Pagination\n- Cursor-based pagination\n- Efficient COUNT queries\n- HATEOAS-compliant responses\n- Optimized for large datasets\n\n### 4. Async Logging\n- Non-blocking log operations\n- Structured logging format\n- Performance monitoring\n- Configurable log levels\n\n### 5. N+1 Query Prevention\n- Strategic JOIN operations\n- Relationship loading optimization\n- Query performance monitoring\n- Efficient indexing strategy\n\n### 6. Compression\n- Content-Encoding negotiation\n- Brotli compression (quality 11)\n- Size-based compression decisions\n- Compression ratio monitoring\n\n### 7. JSON Serialization\n- orjson for optimal performance\n- Custom serializers for complex types\n- Memory optimization\n- Content-type negotiation\n\n## Development\n\n### Prerequisites\n- Docker and Docker Compose\n- Python 3.10+\n- PostgreSQL 15\n- Redis 7\n\n### Local Setup\n1. Install API dependencies:\n   ```bash\n   cd api\n   pip install -r requirements.txt\n   ```\n\n2. Install benchmark dependencies:\n   ```bash\n   cd benchmarks\n   pip install -r requirements.txt\n   ```\n\n### Running Tests\n```bash\n# Run all benchmarks\npython benchmarks/run.py\n\n# Run specific benchmark\npython benchmarks/run.py --technique compression\n```\n\n## Contributing\n\n1. Fork the repository\n2. Create your feature branch\n3. Commit your changes\n4. Push to the branch\n5. Create a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzvdy%2Fapi-performance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzvdy%2Fapi-performance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzvdy%2Fapi-performance/lists"}