MATIH Platform is in active MVP development. Documentation reflects current implementation status.
7. Tenant Lifecycle
Resource Management
Resource Quotas

Resource Quotas

The ResourceQuotaController at /api/v1/tenants/{tenantId}/quotas manages per-tenant resource limits and usage tracking. Quotas are automatically created based on the tenant's tier during provisioning.


Endpoints

MethodPathDescription
POST/quotas/defaultsCreate default quotas for a tenant
POST/quotasCreate or update a quota
GET/quotasGet all quotas
GET/quotas/{resourceType}Get specific quota
GET/quotas/summaryGet quota summary with usage stats
POST/quotas/usageRecord resource usage
GET/quotas/{resourceType}/checkCheck quota availability
GET/quotas/{resourceType}/usage/historyGet usage history
GET/quotas/{resourceType}/usage/trendGet usage trend

Creating Default Quotas

During provisioning, default quotas are created based on the tenant's tier:

curl -X POST http://localhost:8082/api/v1/tenants/{tenantId}/quotas/defaults \
  -H "Authorization: Bearer $TOKEN"

Response (201 Created): Returns a list of ResourceQuota objects with tier-appropriate limits.


Resource Types

The ResourceType enum defines the quotable resources:

Resource TypeDescriptionUnit
CPUCompute coresMillicores
MEMORYRAM allocationMiB
STORAGEPersistent storageGiB
API_CALLSAPI request limitRequests/min
CONNECTIONSDatabase connectionsCount
USERSActive user accountsCount
QUERIESBI/AI query executionsQueries/day
PIPELINESData pipeline slotsCount
MODELSML model deploymentsCount

Creating or Updating a Quota

curl -X POST http://localhost:8082/api/v1/tenants/{tenantId}/quotas \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "resourceType": "API_CALLS",
    "softLimit": 4000,
    "hardLimit": 5000,
    "unit": "requests/min",
    "enforcementMode": "HARD"
  }'

Recording Usage

Services report their resource consumption via the usage endpoint:

curl -X POST http://localhost:8082/api/v1/tenants/{tenantId}/quotas/usage \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "resourceType": "API_CALLS",
    "amount": 150,
    "source": "ai-service"
  }'

Successful Response (200 OK):

{
  "accepted": true,
  "resourceType": "API_CALLS",
  "currentUsage": 3250,
  "softLimit": 4000,
  "hardLimit": 5000,
  "utilizationPercent": 65.0,
  "warningIssued": false
}

Quota Exceeded Response (403 Forbidden):

{
  "accepted": false,
  "resourceType": "API_CALLS",
  "currentUsage": 5000,
  "softLimit": 4000,
  "hardLimit": 5000,
  "utilizationPercent": 100.0,
  "message": "Hard quota exceeded for API_CALLS"
}

Checking Quota Availability

Before consuming a resource, services can check if the request would exceed the quota:

curl "http://localhost:8082/api/v1/tenants/{tenantId}/quotas/API_CALLS/check?amount=500" \
  -H "Authorization: Bearer $TOKEN"

Returns a QuotaCheckResult with availability status.


Quota Summary

curl http://localhost:8082/api/v1/tenants/{tenantId}/quotas/summary \
  -H "Authorization: Bearer $TOKEN"

Returns a QuotaSummary with all quotas, current usage, and utilization percentages.


Usage History

Retrieve historical usage data for a specific resource type:

curl "http://localhost:8082/api/v1/tenants/{tenantId}/quotas/API_CALLS/usage/history?start=2026-02-01T00:00:00Z&end=2026-02-12T00:00:00Z" \
  -H "Authorization: Bearer $TOKEN"

Defaults to the last 7 days if start and end are not provided.


Usage Trend

Get aggregated usage trend data:

curl "http://localhost:8082/api/v1/tenants/{tenantId}/quotas/STORAGE/usage/trend?interval=day" \
  -H "Authorization: Bearer $TOKEN"

Parameters:

  • start: Start time (ISO-8601), defaults to last 30 days
  • end: End time (ISO-8601), defaults to now
  • interval: Aggregation interval (hour, day, week), defaults to day

Source Files

FilePath
Controllercontrol-plane/tenant-service/src/main/java/com/matih/tenant/controller/ResourceQuotaController.java
Servicecontrol-plane/tenant-service/src/main/java/com/matih/tenant/service/ResourceQuotaService.java
Quota Entitycontrol-plane/tenant-service/src/main/java/com/matih/tenant/entity/ResourceQuota.java
Usage Entitycontrol-plane/tenant-service/src/main/java/com/matih/tenant/entity/ResourceUsage.java