Quota Service
Real-time quota tracking and plan enforcement for multi-tenant rate limiting and resource caps
Quota Service (Port 6380)
The quota-service is a high-performance service responsible for real-time tracking of resource usage and enforcing plan-based limits across the MQUAD platform.
Infrastructure
- Port: 6380 (Internal & External)
- Primary Cache: Redis (Shared with core services)
- Mode: Real-time counter-based enforcement
Core Responsibility
The service tracks consumption for key resources:
- Surveys: Total count of surveys per tenant.
- Responses: Monthly submission counts.
- Storage: Total binary storage used (MB).
- Webhooks: Count of active webhook subscriptions.
- Team Members: Count of active users per tenant.
Integration Flow
- A domain service (e.g.,
data-service) receives a request (e.g.,POST /responses). - The domain service calls
GET /check-quota/{tenant_id}/{feature_key}on the quota-service. - The quota-service retrieves the tenant's plan tier from
feature-flags-service. - The quota-service checks the current usage counter in Redis.
- If under the limit, a success code is returned; otherwise, a
403 Forbidden(Quota Exceeded) is issued. - After the action is completed, the domain service calls
POST /increment/{tenant_id}/{feature_key}to update the count.
Redis Counter Keys
Usage counters are stored in Redis using the following pattern:
quota:{tenant_id}:{feature_key}:{period_suffix}
Example: quota:550e8400-e29b-41d4-a716-446655440000:responses:2025-05
Key Endpoints
| Method | Path | Purpose |
|---|---|---|
| GET | /check/{tenant_id}/{key} | Check if tenant has remaining quota |
| POST | /increment/{tenant_id}/{key} | Increment usage for a specific feature |
| POST | /decrement/{tenant_id}/{key} | Decrement usage (e.g., on survey deletion) |
| GET | /usage/{tenant_id} | Get summary of all usage for a tenant |
| POST | /reset/{tenant_id} | Manual reset of tenant quotas (e.g., on plan upgrade) |
Configuration
Standard plan limits are managed via the feature-flags-service, but the quota-service handles the atomic increment/decrement logic to ensure consistency across distributed microservice instances.
