dbt for Crowdsourced Data Quality Testing & Alerting at FINN
Tags: dbt, datawarehouse, engineering, testing
Published: 2022-03-21 20:35:30

This article is a sneak peek at how we ensure data quality at [FINN](https://www.finn.auto/en-US). It explains why we monitor and alert on data quality, which data quality is essential to us, and how we implemented it via dbt. Furthermore, the article illustrates how it can leverage the distributed knowledge regarding business processes by allowing all teams to contribute to data quality.

### The impact of this on FINN
- More than 70% of business logic data testing comes from people who are not part of our core data engineering team.
- 100% of all operational departments at FINN contribute data tests.
- So far, hundreds of data tests have been implemented in a decentralized ("crowd sourced") manner within one quarter.

### Background - What is dbt?

> "dbt is a transformation workflow that lets teams quickly and collaboratively deploy analytics code following software engineering best practices like modularity, portability, CI/CD, and documentation. Now anyone who knows SQL can build production-grade data pipelines." [source](https://www.getdbt.com/product/what-is-dbt/)

### Why [FINN](https://www.finn.auto/en-US) monitors and alerts on data quality.

[FINN's](https://www.finn.auto/en-US) growth in 2021 caused challenges for the entire technical infrastructure. [FINN](https://www.finn.auto/en-US) has grown 10x in the number of signed subscriptions, and the number of employees doubled in 6 months.

During this growth, data-generating business processes change rapidly to evolve [FINN's](https://www.finn.auto/en-US) products. This rapid development challenges data warehousing since any change in business logic needs to be considered in the data pipelines to keep analytics valid. Further, moving physical assets (cars) is challenging since many things can go wrong in the non-digital world.

To generate bulletproof analyses of the entire fleet/business state at any point in time, the data engineering team has to build a scalable/successful data platform on which analytics, data science, and machine learning teams can build.

### A successful data platform ensures data quality.

One success metric of [FINN's](https://www.finn.auto/en-US) data platform is the quality of the data we provide to other teams. Hence, we developed a technical solution to test data quality, alert data owners, track data quality over time, and enable all teams to contribute tests.
 
More specifically, we need to test things like:

- Basic data quality: uniqueness, nullness, types, accepted values
- Business logic: "Signed subscriptions need to have fields xyz filled", "Cars in state x need to have fields xyz filled with"

### The contribution to data quality should be decentralized.

The data engineering team shouldn't be the bottleneck for data quality tests. The experts in business logic are part of mission-based teams. Therefore, each team should implement tests for data generated by their processes.

### The requirements we set for the target system.

- Req-1: Different teams implement tests in a non-centralized way.
- Req-2: Data quality tests should be easy to implement via SQL.
- Req-3: We send out notifications to corresponding teams via Slack for each test.
- Req-4: We track a history regarding test performance.

### The target architecture and execution.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6w8jouz8ptxq0ro174ae.jpeg)

The picture shows the following components (left to right):

- `model.yml`: yml files that are part of a git repository next to data model definitions. These files are typically used in a dbt project to [document data models and run tests at column or table level](https://docs.getdbt.com/tutorial/test-and-document-your-project).
- `FINN DWH dbt GIT Repo`: The git repository contains all of FINNs data models and corresponding documentation.
- `dbt Cloud Internals`: dbt cloud executes scheduled data transformations to create the data models (tables) (defined in the git repository). Those scheduled data transformations create `job Artefacts` that we fetch via `dbt Cloud API`.
- `DWH dbt_tests_output`: Tables in our data warehouse that contain details of failing rows.
- `FINN Data Quality Alerting Service`: An ~~Integromat~~ [make](https://www.make.com/en) scenario that implements some logic to get job artefacts from dbt cloud, get the corresponding failing rows from the data warehouse, and forward those test results to corresponding slack channels.

The execution looks like this:

1. A scheduled (hourly) dbt cloud job runs `dbt test –store-failures` (running on dbt version v1.0.0).
2. According to the [model configurations](https://docs.getdbt.com/reference/model-configs) (.yml files), the tests (SQL/[dbt macros](https://docs.getdbt.com/docs/building-a-dbt-project/jinja-macros)) are executed on column and table levels. Job artifacts are saved.
3. The Data Quality Alerting Service (an ~~Integromat~~ [make](https://www.make.com/en) scenario) fetches the job artifacts via [dbt Cloud API](https://docs.getdbt.com/dbt-cloud/api-v2).
4. The service queries corresponding results (failed rows) from the data warehouse according to the artifacts.
5. The service sends failing rows to the corresponding team (Slack channel), including a resolution description.

Let's break down the requirements step by step.

### ✅ Req-1: The central pillar of the system outlined above is dbt. It enables a decentralized data testing workflow (and much more). 

[dbt](https://docs.getdbt.com/docs/introduction) is particularly good at performing data transformations. The tooling around dbt lets our data people work in a development workflow that feels like software engineering. Other teams, which don't focus on data engineering, are also empowered to contribute changes to data transformations. Pull requests, code reviews, data tests, and column profiling (via [Datafold](https://www.datafold.com/)) ensure changes don't break downstream data models. These features allow us to scale data (test) engineering decentralized across teams.

(Our data stack: [Fivetran](https://www.fivetran.com/), [BigQuery](https://cloud.google.com/bigquery), [dbt](https://www.getdbt.com/), dbt Cloud, [Looker](https://www.looker.com/), [Datafold](https://www.datafold.com/))

### ✅ Req-2: Straightforward SQL to implement the tests.

The following image shows an exemplary data quality test. The configuration specifies the Slack channel to be alerted, while the description should help the corresponding team to resolve failing tests.

The SQL statement describes how to query for wrong rows. If the query returns more than 0 rows, these incorrect rows are reported in the Slack channel and resolved immediately.

```sql
{{ config(
    enabled=True,
    tags= ['fleet_alert', 'fleet_intelligence_data_quality_alerts'],
    description= 'Test to verify VIN aligning between invoice and fleet car'
) }}

WITH cars AS (
    SELECT
        cars.vin AS fleet_car_vin,
        invoices.invoice_vin AS invoice_vin,
        cars.lookup_financing_partner
    FROM cars
    LEFT JOIN invoices
        ON cars.finn_car_unit_id = invoices.finn_car_unit_id
)

SELECT *
FROM cars
WHERE invoice_vin != fleet_car_vin
```
### ✅ Req-3: The Data Quality Alerting Service sends out alerts 

The service (an ~~Integromat~~ [make](https://www.make.com/en) scenario) frequently looks for new test results via the dbt Cloud API, fetches the corresponding faulty (if any) rows from our data warehouse, and sends them to the appropriate Slack channel. The failing rows are manually checked in the data sources and cleaned up from here on.

### ✅ Req-4: Daily snapshots of test outputs enable tracking over time 

We take daily snapshots of test results, aggregate them, and send [Looker](https://looker.com/) dashboards to the appropriate teams.

### Thanks for reading! 💜

Feel free to reach out on [LinkedIn](https://www.linkedin.com/in/jorrit-p-13461674/) or comment here if you're interested in further details.

**Contributors & Social Links**
Felix - Data Products Manager: [LinkedIn](https://www.linkedin.com/in/felix-kreitschmann/)
Shahbal - Data Engineer: [LinkedIn](https://www.linkedin.com/in/shahbalkhan/)
Philipp - Senior Data Products Manager: [LinkedIn](https://www.linkedin.com/in/philipp-wohnhaas-2172b7164/)
Alex - VP Data Engineering: [LinkedIn](https://www.linkedin.com/in/alexanderyasnogor/)
Jorrit - Tech Lead Data Engineering: [Twitter](https://twitter.com/jposor), [LinkedIn](https://www.linkedin.com/in/jorrit-p-13461674/)

**Next Steps:**
- Open-source the implementations
- Blogpost: The data stack at [FINN](https://www.finn.auto/en-US)

**More articles by [FINN](https://www.finn.auto/en-US) engineers:**
- [Running a startup with No Code - until when?](https://dev.to/ebsaral/running-a-startup-with-no-code-until-when-4llj)
- [How did we tackle Airtable's API limits at FINN?](https://dev.to/ebsaral/how-did-we-tackle-airtables-api-limits-at-finn-5h71)

### By the way, [we're hiring](https://www.finn.auto/careers)! (also remote/US)
- [FINN on LinkedIn](https://www.linkedin.com/company/finn-auto/posts/?feedView=all).
- [Among the top 10 LinkedIn startups](https://www.linkedin.com/pulse/linkedin-top-startups-2021-zehn-junge-top-unternehmen-/) in Germany.
- [Top reviews on Glassdoor](https://www.glassdoor.de/Bewertungen/Bewertungen-FINN-RVW53192413.htm).
- Tons to learn + incredible people. 🚀

Thanks to [Johannes Klumpe](https://www.linkedin.com/in/klumpe/) and [Gregor Albrecht](https://www.linkedin.com/in/gregoralbrecht/) for reading drafts of this!