Skip to content

Conversation

@koxudaxi
Copy link
Collaborator

@koxudaxi koxudaxi commented Jan 6, 2026

TL;DR

Added an outbox processor for ClickHouse synchronization that handles span data extraction, transformation, and insertion.

What changed?

Created a new outboxProcessor.ts file that implements a robust system for synchronizing span data from PostgreSQL to ClickHouse. The processor:

  • Defines types for outbox messages and ClickHouse analytics rows
  • Implements utility functions for backoff calculation, error sanitization, and attribute extraction
  • Provides a transformation function to convert spans to ClickHouse format
  • Implements a main processing function that:
    • Locks outbox rows to prevent duplicate processing
    • Extracts span and trace data from PostgreSQL
    • Transforms data to ClickHouse format
    • Handles batch insertion with retry logic
    • Updates outbox status based on processing results

How to test?

  1. Create outbox messages for spans that need to be synchronized
  2. Verify the processor correctly extracts and transforms span data
  3. Confirm successful insertion into ClickHouse's spans_analytics table
  4. Check error handling by simulating failures and verifying retry behavior
  5. Verify outbox status updates correctly after processing

Why make this change?

This implementation provides a reliable mechanism for synchronizing span data to ClickHouse for analytics purposes. The outbox pattern ensures data consistency between PostgreSQL and ClickHouse, with features like:

  • Exponential backoff for retries
  • Error tracking and limiting
  • Proper locking to prevent duplicate processing
  • Efficient batch processing
  • Shared logic that can be used by both queue consumers and polling workers

Copy link
Collaborator Author

koxudaxi commented Jan 6, 2026

@koxudaxi koxudaxi marked this pull request as ready for review January 6, 2026 06:51
@koxudaxi koxudaxi requested a review from willbakst as a code owner January 6, 2026 06:51
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 6, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
v2-docs a296314 Jan 09 2026, 03:57 AM

@koxudaxi koxudaxi force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 80a1533 to 1d2fda8 Compare January 6, 2026 07:55
@koxudaxi koxudaxi force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch 2 times, most recently from 6abb2ce to 0b11879 Compare January 6, 2026 08:14
@koxudaxi koxudaxi force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 1d2fda8 to 150b7ad Compare January 6, 2026 08:14
@koxudaxi koxudaxi force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 150b7ad to 0bd5bf4 Compare January 6, 2026 08:22
@koxudaxi koxudaxi force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch 2 times, most recently from dad5c76 to c126a39 Compare January 6, 2026 08:22
@koxudaxi koxudaxi force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 0bd5bf4 to bcf092c Compare January 6, 2026 08:22
@koxudaxi koxudaxi force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch from c126a39 to 1d8de59 Compare January 6, 2026 08:32
@koxudaxi koxudaxi force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch 2 times, most recently from 495a3e7 to 9700c2e Compare January 6, 2026 08:36
@koxudaxi koxudaxi force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch 2 times, most recently from d9ae300 to 4c878c7 Compare January 6, 2026 08:41
@koxudaxi koxudaxi force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch 2 times, most recently from ab157f5 to 7e41a1d Compare January 6, 2026 08:44
@koxudaxi koxudaxi force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch from 4c878c7 to e68492f Compare January 6, 2026 08:44
@koxudaxi koxudaxi force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 7e41a1d to 464a232 Compare January 6, 2026 08:45
@koxudaxi koxudaxi force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch from e68492f to 754e297 Compare January 6, 2026 08:45
@koxudaxi koxudaxi force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch from b498dab to 5866958 Compare January 8, 2026 13:25
@koxudaxi koxudaxi force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch from 5866958 to 0084b89 Compare January 8, 2026 14:33
@koxudaxi koxudaxi force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch 2 times, most recently from 0e599c9 to 972673c Compare January 8, 2026 14:36
@koxudaxi koxudaxi force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch from 0084b89 to 2fbd108 Compare January 8, 2026 14:36
@koxudaxi koxudaxi force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 972673c to cdbd95f Compare January 8, 2026 18:03
@koxudaxi koxudaxi force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch 2 times, most recently from f2d94a8 to e0e4fcc Compare January 8, 2026 18:09
@koxudaxi koxudaxi force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from cdbd95f to 8d369f2 Compare January 8, 2026 18:09
Copy link
Collaborator

willbakst commented Jan 9, 2026

Merge activity

@koxudaxi koxudaxi force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch from e0e4fcc to f9cdc37 Compare January 9, 2026 03:11
@koxudaxi koxudaxi force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 8d369f2 to 3732ae8 Compare January 9, 2026 03:11
@willbakst willbakst force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch from f9cdc37 to 468bbb7 Compare January 9, 2026 03:17
@willbakst willbakst force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 3732ae8 to 6767d43 Compare January 9, 2026 03:18
@willbakst willbakst force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch from 468bbb7 to f6c812d Compare January 9, 2026 03:25
@willbakst willbakst force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 6767d43 to a03ba4b Compare January 9, 2026 03:26
@willbakst willbakst force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch from f6c812d to 41d2ebc Compare January 9, 2026 03:32
@willbakst willbakst force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from a03ba4b to 861d7ad Compare January 9, 2026 03:32
@willbakst willbakst force-pushed the 01-06-feat_db_write_to_outbox_on_span_insertion branch 2 times, most recently from 345841f to fdc0d42 Compare January 9, 2026 03:38
@willbakst willbakst force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 861d7ad to 2857a3c Compare January 9, 2026 03:39
@willbakst willbakst changed the base branch from 01-06-feat_db_write_to_outbox_on_span_insertion to graphite-base/1811 January 9, 2026 03:45
@willbakst willbakst force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 2857a3c to 861393d Compare January 9, 2026 03:45
@graphite-app graphite-app bot changed the base branch from graphite-base/1811 to v2 January 9, 2026 03:45
@willbakst willbakst force-pushed the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch from 861393d to a296314 Compare January 9, 2026 03:45
@willbakst willbakst merged commit 0de418b into v2 Jan 9, 2026
10 checks passed
@willbakst willbakst deleted the 01-06-feat_workers_implement_outbox_processor_for_clickhouse_sync branch January 9, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants