Skip to main content

Data Flow

This document traces how data moves through the entire system, from time tracking in Jira to final payment.

End-to-End Flow

Data Sources

Jira + Tempo → ClickHouse

n8n workflows run on a schedule (~15 min) and sync:

SourceDestinationData
Tempo APItempo.worklogs_flatTime entries with duration, user, date, project
Jira APIjira.jira_issuesIssue metadata (type, priority, summary)
CDM pipelinecdm.jira_applicationsClient deals with amounts, rates, limits
CDM pipelinecdm.jira_customersCompany details, TIN, SWIFT, signers
CDM pipelinecdm.jira_contactsClient contact persons

ClickHouse → Prefill → PostgreSQL

The prefill pipeline reads from ClickHouse and produces structured data:

ClickHouse (worklogs + issues + application + customer)
↓ categorize, apply min billable, calculate financials
Prefill Result (preview, not saved)
↓ user confirms
PostgreSQL (invoice + line_items + events)

PostgreSQL → PDF → External Systems

After finalization:

PostgreSQL (invoice + line_items)
↓ render HTML template
Gotenberg (HTML → PDF)
↓ save PDF
PostgreSQL (pdf_data column)
↓ on approval
PlanFact (accounting sync)
Cloudflare R2 (PDF storage)
Didox.uz / Email (delivery)

Data Ownership

DataOwnerStorageMutability
WorklogsTempoClickHouseRead-only (synced by n8n)
Jira issuesJiraClickHouseRead-only (synced by n8n)
Client infoCDMClickHouseRead-only (synced by CDM pipeline)
InvoicesInvoice appPostgreSQLRead-write
Line itemsInvoice appPostgreSQLRead-write
Events/historyInvoice appPostgreSQLAppend-only
Rate rulesInvoice appPostgreSQLRead-write
PDFsInvoice appPostgreSQL (Phase 1), R2 (Phase 3)Immutable after generation
App settingsInvoice appPostgreSQLRead-write

Timing Considerations

OperationTypical DurationTimeout
ClickHouse query100-500ms15s
PostgreSQL query5-50ms5s
PDF generation1-5s30s
PlanFact API call200-1000ms10s
n8n data syncEvery ~15 minN/A

The main latency concern is data freshness: worklogs logged in Tempo may take up to 15 minutes to appear in ClickHouse. The prefill pipeline always reads the latest available data.