Hey There, #NeedHelpWithMultiTenancy I have recent...
# replication-troubleshooting
p
Hey There, #NeedHelpWithMultiTenancy I have recently started using Airbyte, I am using the cloud version. I was able to setup the source and destination. The use case is multi source and single destination. The issue i am facing is I am not able to identify which row belongs to which source. So, essentially I want to add some metadata identifiers in the data before it reaches the destination so that I can identify and implement my business logic. Can somebody help on this.
k
Certainly! In Airbyte, when you have multiple sources syncing to a single destination, distinguishing which row came from which source is a common multi-tenancy challenge. Best Practices: 1. Add Source Identifiers via Metadata: - Airbyte automatically appends metadata fields to each record, such as
_airbyte_raw_id
,
_airbyte_extracted_at
, and
_airbyte_meta
. However, these do not include a source identifier by default—they are more for tracking and debugging purposes, not for identifying the source system of each row. - To solve your use case, you should add a custom field (e.g.,
source_id
or
tenant_id
) in your source data or use Airbyte transformations (if available in your plan) to inject such a field before the data lands in the destination. This way, each row will carry an explicit identifier for its origin. - Alternatively, you can use table prefixes or namespaces to separate data from different sources, but this results in multiple tables rather than a single combined table. 2. Cloud Version Considerations: - In Airbyte Cloud, you can configure what fields are included in your destination data by adjusting the schema during connection setup. However, there is no built-in feature to automatically add a source identifier for each row unless you include it in your source data or use a transformation step. 3. Community Recommendations: - The Airbyte community suggests using custom DBT transformations to add a
source
or
tenant
column when merging data from multiple sources into a single table. This is a common approach for multi-tenancy and downstream business logic. - You can also use table prefixes or custom namespaces to keep data separated if you prefer not to merge everything into a single table, but this may not fit your use case if you want all data together for analysis. - See this community discussion for more context: using a custom column or DBT transformation is a recommended solution for tracking the source of each row [Forum: Manage multiple sources sync to the same tables](https://discuss.airbyte.io/t/323). Summary Table: | Approach | How to Implement | Pros/Cons | |-------------------------|------------------------------------------------------|--------------------------------------------| | Add custom field | Add
source_id
in source or via transformation | Most flexible, works for all destinations | | Table prefix/namespace | Use Airbyte's prefix/namespace options | Keeps data separate, but in multiple tables| | DBT transformation | Add column during DBT model merge | Powerful, but requires DBT setup | Next Steps: - If you control the source, add a source identifier field to your data. - If not, use Airbyte transformations or DBT to inject the identifier. - Adjust your connection schema to ensure the new field is included in the destination. If you need step-by-step guidance on setting up transformations or DBT with Airbyte Cloud, let me know!
p
I cannot control the source data as our customers own the connectors. Currently I am in trial would be getting in a paid plan once I complete my POC. It would be great if you can help me with Step by step guidance for transformation in Airbyte Cloud. @kapa.ai
k
A message from kapa.ai
Certainly! Here’s a step-by-step guide for adding transformations in Airbyte Cloud using the dbt Cloud integration, which is the supported way to perform post-sync transformations in Airbyte Cloud: --- ### Step 1: Prerequisites - You need a paid version of dbt Cloud (the integration does not work with the free tier). - Generate a dbt Cloud service token with Member, Job Admin, or Account Admin permissions. [How to generate a service token](https://docs.getdbt.com/docs/dbt-cloud-apis/service-tokens#generate-service-account-tokens). --- ### Step 2: Set Up dbt Cloud Integration in Airbyte Cloud 1. In Airbyte Cloud, go to Settings > Integrations. 2. Enter your dbt Cloud access URL (e.g., `https://cloud.getdbt.com/`). 3. Enter your dbt Cloud service token. 4. Click Save changes. --- ### Step 3: Add a dbt Transformation to a Connection 1. Go to Connections and select the connection you want to transform. 2. Navigate to the Transformation tab. 3. Click + Add transformation. 4. Select the dbt job you want to run from the dropdown. 5. Click Save changes. - The dbt job will now run after each sync for this connection. - You can add multiple transformations if needed. - To remove a transformation, click the X next to it and save changes. --- ### How to Add a Source Identifier - In your dbt model, add a column (e.g.,
source_id
) and set its value to identify the source. - Example SQL in your dbt model:
Copy code
sql     select       *,       'source_name_or_id' as source_id     from {{ ref('your_airbyte_table') }}
- You’ll need a separate dbt job/model for each source, or use logic in dbt to set the identifier based on the table or schema. --- Note: - Custom transformations (like adding columns before data lands in the destination) are not available in Airbyte Open-Source, only in Airbyte Cloud via dbt integration. - The dbt job runs after the sync, so the identifier is added in the transformation step, not during extraction or loading. For more details, see the official documentation: [dbt Cloud integration in Airbyte Cloud](https://docs.airbyte.com/platform/cloud/managing-airbyte-cloud/dbt-cloud-integration). If you need help with the dbt model SQL or further setup, let me know!
p
what if i dont have a dbt cloud paid ? @kapa.ai
k
A message from kapa.ai
If you do not have a paid dbt Cloud account, you will not be able to use the dbt Cloud integration for custom transformations in Airbyte Cloud. The documentation clearly states that the dbt Cloud integration requires a paid version of dbt Cloud, and custom transformations are not available for Airbyte Open-Source either. There is no mention in the knowledge sources of an alternative built-in way to add custom fields or perform post-sync transformations in Airbyte Cloud without dbt Cloud paid integration [dbt Cloud integration](https://docs.airbyte.com/platform/cloud/managing-airbyte-cloud/dbt-cloud-integration) [Custom Transformations](https://docs.airbyte.com/platform/using-airbyte/core-concepts#custom-transformations). If you need to add metadata identifiers and do not have access to dbt Cloud paid, the knowledge sources do not provide a supported method to achieve this directly within Airbyte Cloud.
j
Depending on your destination, you would often split these out by schema. For example, if you're using BigQuery, "schema" in the destination settings would be the BigQuery dataset. So you could put each source system or "client" their own dataset to keep them isolated and be able to separately permission them. Other destinations tend to have other options like this, but the naming of what schema maps to can be different. In our case (which is largely managed over the API), we use schema/dataset to split out the client-level groupings, and then add a prefix to each connector denoting its type and a unique identifier. So the resulting streams have a prefix like:
our-project.[client_name]_[client_id].hubspot_123_*
This works well for us and ensures that streams group together for each instance of a connection and avoids stream/table name conflicts between connections or for multiple instances of the same type of connection (e.g. if a client has multiple Facebook Ads accounts). This lets you still use a single destination, but still have some separation of the output data at both a client and connection level.
p
Thanks @Justin Beasley for this information. Our use case is like following. Our destination is clickhouse and we want to consolidate the data to run analytics on that data. If we keep it in a different data set it would be difficult to query on different tables or schema for every customer. That is why it gets difficult to manage different tables for the different streams from different source connectors. Any thoughts on this?
j
in ClickHouse I would still keep them separate (either database or table names) and use Merge: https://clickhouse.com/docs/engines/table-engines/special/merge Basically you could keep them separate with client-level prefixes, and match them with a regex to read across the different sources. Also works across databases.
p
Thanks @Justin Beasley for this information.
👍 1