Data Service
Response data storage, processing, bulk operations, and export pipeline
Data Service (Port 8002)
The data-service manages survey response data, attachments, bulk operations, and exports. It serves as the primary repository for all collected field data.
Database
Database: data_db
| Table | Purpose |
|---|---|
responses | Survey response data (JSONB answers) |
attachments | File attachments linked to specific question IDs |
API Endpoints
| Method | Path | Purpose |
|---|---|---|
| GET | /api/v1/responses | List responses (paginated) |
| POST | /api/v1/responses | Submit a new response |
| GET | /api/v1/responses/{id} | Get full response and history |
| PATCH | /api/v1/responses/{id} | Update specific response values |
| DELETE | /api/v1/responses/{id} | Permanently delete a response |
| POST | /api/v1/responses/{id}/approve | Approve a response (workflow) |
| GET | /api/v1/responses/{id}/attachments | List all files for this response |
| POST | /api/v1/bulk | Batch status updates or deletions |
Attachment Management
The data-service coordinates with the media-service for file handling:
- When a survey includes media questions (Image, Signature, etc.), the client uploads the file to
media-service. - The resulting
asset_idis stored in theresponsestable. - The
attachmentstable links these assets to the specific response for easy retrieval.
Export Pipeline
The service supports large-scale data exports in multiple formats:
- Formats: CSV, XLSX, JSON.
- Async Execution: Exports are processed via Celery to prevent API timeouts for large datasets.
- Workflow:
- Client triggers export via
POST /api/v1/export. - Service initiates a task and returns a task ID.
- Client polls for completion.
- Finished file is served via a temporary download URL.
- Client triggers export via
Events Published
Events are published to the Redis webhook:events channel:
response.submittedresponse.approvedresponse.deleted
# Event payload structure
{
"event_type": "response.submitted",
"tenant_id": "uuid",
"data": {
"response_id": "uuid",
"survey_id": "uuid"
}
}