Skip to contentManaged Kafka is live: Apache Kafka on AWS for half the cost of MSK

Using Artie

Write to multiple destinations

Split an existing pipeline into a shared source reader and independently replicate its changes to two destinations.

A shared source reader captures the source’s change data capture (CDC) stream once, and each pipeline on it consumes that stream independently. This guide starts with an existing PostgreSQL to Snowflake pipeline and adds BigQuery as a second destination.

The same steps work for other source and destination combinations, with two exceptions. An S3 source reader can’t be shared, and a source reader can’t be shared while one of its pipelines writes to a Kafka destination.

Prerequisites

Sharing a source reader is configured only through Terraform. The dashboard has no setting for it. Before you start, check that you have:

  • The existing pipeline and its source reader managed in Terraform, or imported into Terraform state.
  • The Artie Terraform provider configured with an Artie API key.
  • An artie_connector for each destination. This guide uses snowflake_analytics and bigquery_lake.
  • The full list of source tables that either destination needs.
  • Permission to run terraform plan and terraform apply.

Shared source readers

Before the change, the source reader is dedicated to one pipeline:

KafkaPostgreSQLSource ReaderSnowflake Pipeline

After the change, the same reader publishes one change stream and both pipelines consume it independently:

KafkaKafkaPostgreSQLShared Source ReaderSnowflake PipelineBigQuery Pipeline

Each pipeline owns its destination configuration, table settings, backfill, and stream position. Changing one pipeline’s destination settings doesn’t change the other pipeline. The shared source reader owns which source tables Artie captures.

Share the reader and add a pipeline

Make each change in your Terraform configuration and apply it before you start the next step.

  1. Make the existing source reader shared

    Add is_shared = true to the existing artie_source_reader and declare its tables map. The map must include every table in every pipeline that references the reader.

    This example shares the reader and captures public.customers and public.orders:

    terraform
    resource "artie_source_reader" "postgres_production" {
      name                               = "Postgres Production Reader"
      connector_uuid                     = artie_connector.postgres_production.uuid
      database_name                      = "app"
      postgres_replication_slot_override = "artie_reader"
    
      is_shared = true
    
      # Capture every table needed by either pipeline.
      tables = {
        "public.customers" = {
          name   = "customers"
          schema = "public"
        }
        "public.orders" = {
          name   = "orders"
          schema = "public"
        }
      }
    }

    Keep the source reader’s existing connection and source-specific settings. Terraform rejects is_shared = true when the tables map is missing or empty.

    Run terraform plan and confirm that only the source reader changes, then run terraform apply. After the update, the provider deploys the shared source reader.

  2. Verify the existing pipeline

    The existing pipeline already references this source reader, so sharing the reader needs no pipeline change. Keep the pipeline’s destination configuration and table selection.

    Confirm that its source_reader_uuid still references artie_source_reader.postgres_production.uuid. Don’t copy or reapply the pipeline resource only to share the reader, especially when you imported the pipeline into Terraform.

  3. Add a second pipeline for the new destination

    Create another artie_pipeline that references the same source_reader_uuid and a different destination connector. A pipeline can replicate a subset of the reader’s captured tables.

    terraform
    resource "artie_pipeline" "postgres_to_bigquery" {
      name               = "PostgreSQL to BigQuery"
      source_reader_uuid = artie_source_reader.postgres_production.uuid
    
      destination_connector_uuid = artie_connector.bigquery_lake.uuid
      destination_config = {
        dataset = "product_analytics"
      }
    
      # BigQuery receives orders only. The shared reader still captures
      # customers because the Snowflake pipeline needs it.
      tables = {
        "public.orders" = {
          name   = "orders"
          schema = "public"
        }
      }
    }

    Run terraform plan and confirm that Terraform creates only the new pipeline. Then run terraform apply.

    Artie backfills the new pipeline’s tables into BigQuery, then consumes live changes from the shared reader. The existing Snowflake pipeline continues from its own position throughout the backfill.

Verify both destinations

Wait for the new pipeline’s backfill to complete and its lag to reach your normal operating range in the analytics portal. Then check the new destination before you rely on it:

  • Compare row counts for each newly replicated table.
  • Spot-check recent inserts, updates, and deletes.
  • Run representative downstream queries against both destinations.
  • Confirm that the existing pipeline remains healthy while the new pipeline catches up.

Add another table later

Add a table to the shared reader’s tables map before you add it to a pipeline, unless the map already has it. The reader must capture a table before any pipeline on it consumes that table.

For example, to send public.refunds only to BigQuery:

  1. Add public.refunds to artie_source_reader.postgres_production.tables.
  2. Apply the source reader change.
  3. Add public.refunds to artie_pipeline.postgres_to_bigquery.tables.
  4. Apply the pipeline change and monitor its backfill.

A pipeline table that the reader doesn’t capture fails pipeline validation with this error:

Text
shared source reader does not have a table config for table "public.refunds"

Frequently asked questions

These answers cover what the pipelines on a shared source reader share and what each pipeline sets for itself.

Does this create another replication slot or source reader?

No. Both pipelines reference the same artie_source_reader, so Artie captures the source change stream once and fans it out to the pipelines on that reader.

Can the two pipelines replicate different tables?

Yes. Each pipeline has its own tables map. The shared source reader’s map must include the union of all tables used by every pipeline on it.

Can the pipelines use different table settings?

Yes. Destination-specific settings belong to each pipeline: an alias, history mode, column inclusion, and destination configuration. Source capture settings belong to the shared reader and apply to every pipeline on it.

The reader’s column lists limit every pipeline. When the reader’s table sets columns_to_include, a pipeline’s columns_to_include for that table must list only columns from the reader’s list.

Can I add more than two destinations?

Yes. Add another artie_pipeline that references the same shared reader. Keep the reader’s tables map aligned with the union of all pipelines on it.

Can I switch the reader back to a dedicated reader later?

Yes, once at most one pipeline references it. Set is_shared = false, remove the reader’s tables map, and apply. See online migration for the full conversion steps.

With more than one pipeline on the reader, Artie rejects the change with this error:

Text
this source reader is being used by multiple pipelines so it cannot be set to not shared

Was this page helpful?