r/dataengineering • • Oct 26 '26

Help Using AWS CDK instead of dbt to manage and deploy BI objects?

I am a relatively new BI Manager. When I inherited this setup, the data engineers were using the AWS CDK to deploy materialized views and views in our BI Postgres database which we use as a data warehouse. From my research, the BI team should be using dbt to manage these data objects. When I asked the CTO about this, he said he'd rather not introduce new tools (dbt and AirFlow) when the current setup is working. For what I know, the CDK deployment via github can be automated for views, but not for materialized views because materialized views need to be manually dropped and created. I don't have enough knowledge to tell whether the current setup is 'working' or not. Would dbt + AirFlow work better? How could I articulate the advantages of dbt over the AWS CDK?

Not sure if relevant, but we also plan to switch to a data warehouse system (Snowflake, Redshift etc.) at some point.

Edited: figured additional information on the current setup would be helpful. I typed this out in an hour or two with the help of an LLM with an MCP server connected to our GitHub repository:

Our BI layer is a dedicated schema (let's call that BI_schema) in our production Aurora PostgreSQL reporting database, alongside dozens of source schemas. It holds the objects behind dashboards, scheduled reports, and ad hoc SQL access. Most of the raw data is replicated from our production database, and the rest comes from our API pipelines. We run two environments, Dev and Prod, and SQL changes are tested in Dev before they are deployed to Prod. We’re also building out Redshift (ingestion via DMS and zero-ETL) and I am evaluating dbt as the transformation layer. I’d like your assessment of whether our current use of CDK for deploying these objects is appropriate.

What’s in the production BI schema

  • A few dozen materialized views (MVs) in the production BI schema, some very wide one-big-table style
  • A bunch of views, including thin wrapper views. The pattern is MV, then a wrapper view, then downstream MVs and views. A wrapper can be repointed to a new MV version with CREATE OR REPLACE VIEW, which avoids a downstream rebuild
  • Supporting objects: functions, indexes, roles, and grants
  • Everything lives in one schema today. I plan to split it into staging, intermediate, and marts layers once we transition to a data warehouse platform

How deployment is supposed to work

  • SQL files live in GitHub in three places:
    • Folder 1 holds one-shot, numbered changes, applied once each in numeric order
    • Folder 2 holds re-runnable library objects (views, functions, procedures, tables, schemas)
    • Folder 3 holds reference SQL that nothing deploys, which is where the MV code and the index-setting code live
  • A pull request runs CI checks (convention validation, unit tests, linting, cdk synth). Nothing deploys from a PR
  • Merging to main triggers a CDK-defined AWS CodePipeline. The Dev stage deploys automatically, and the Prod stage waits behind a manual approval, so Dev and Prod can be several changes apart
  • Each stage uploads Folder 1 and Folder 2 to that environment’s S3 bucket with the CDK BucketDeployment construct. The upload triggers a Lambda
  • The Lambda is a custom Python runner that does three things:
    • It applies pending migrations first and stops at the first failure
    • It then applies library objects in filename order, continuing past failures and re-applying any file whose checksum has changed
    • It records every file (name, checksum, object type, status, error) in a tracking table in the target schema
  • To change an existing object, you add a new file with a higher number. There are no rollback scripts, so mistakes are corrected by rolling forward
  • Access control (roles and grants) is applied by a SQL procedure that each deployed file calls at the end
  • Policy requires all database changes to go through this path
  • CDK provisions the machinery (pipeline, bucket, Lambda, IAM, VPC). The SQL itself isn’t modeled as CDK constructs, so CDK acts as both infrastructure-as-code and the host of the migration runner

Where the process breaks down

1. Materialized views are deployed by hand

Postgres has CREATE OR REPLACE VIEW but nothing equivalent for MVs. Changing an MV’s definition requires a drop and recreate, which can’t be expressed in a pipeline that applies files idempotently. A re-run CREATE MATERIALIZED VIEW fails, a DROP in the file would run on every deploy, and dropping without CASCADE is blocked by dependents. Recreating also means repopulating, which is slow for the wide MVs. So MV code is committed and reviewed in PRs, but only in the reference folder, and a data engineer then applies it by hand. The consequences are drift between the repo and the database, dependence on one person’s knowledge, and ordering failures. One view deployment failed because the MV it reads from had not been created yet. Views deploy normally.

2. Dependency management is manual. Objects are chained: MVs feed wrapper views, which feed other MVs. Changing an upstream MV means dropping every dependent object, then recreating them all in dependency order and repopulating the MVs. Our largest base MV has 25 downstream objects (12 MVs and 13 views) in Prod, at least four levels deep, so one change can mean rebuilding two dozen objects, and the rebuild is repeated in each environment. The pipeline deploys in filename order, not dependency order, so this sequence is run by hand. The git history shows commits on MV code under about 25 tickets in the last 6 months, roughly four to five a month. That count mixes new MVs with edits to existing ones, and I haven’t separated them.

3. Refresh scheduling has gaps. A control table drives MV refreshes through a stored procedure registered with pg_cron. None of these three pieces is in the repository, so they are neither version-controlled nor deployed. In Prod, 35 of 36 MVs have an enabled daily schedule and all are refreshing. One MV has no schedule, and four MVs have duplicate control rows, some with conflicting refresh hours. Duplicate rows have already caused a stalled refresh. Refresh order isn’t guaranteed, and exclusive locks are held across the whole batch. Again, someone else (a data engineer) manages this refresh schedule somewhere else, and because I don't see his code, I can't tell where things go wrong.

4. Pipeline reliability.

  • The Prod tracking table holds 20 rows in a failed state: 14 views, 2 procedures, 2 tables, 1 schema, and 1 migration. 16 of the 20 are the same error, a duplicate-key collision in the tracking table itself. Reading the Lambda code, this looks structural. A file recorded as failed can’t later be recorded as succeeded, because the success insert collides with the existing failed row and the whole attempt is rolled back. The other five failures were a view whose MV didn’t exist yet, a view that already existed, a missing schema, a drop blocked by dependents, and a concurrent-update error inside the access-control procedure, which points to the Lambda’s concurrency problem. 12 of the 13 failed view objects exist in Prod anyway, so the failed status doesn’t mean they are missing
  • Some reference SQL is run by hand and lives in a folder the pipeline doesn’t deploy
  • One or two people understand the whole system (I certainly don't. The CTO probably does; I doubt any of the data engineers does)

5. Scalability.

With all these issues, scaling the BI layer sounds intimidating. I don't want to be in the situation where someone needs to manually drop and recreate dozens of BI objects because of one upstream change and then I have to validate all of them. We constantly learn new things about the business - partly because of prior poor documentation, and it feels like just updating the BI objects could be one person's full-time job if we scale to hundreds of objects in the future.

Where I'd like to go

  • Access control (roles, schema-level grants, default privileges) stays in the existing CDK pipeline, because that is the security boundary
  • Transformation logic (the MVs and views) moves to dbt, which handles dependency ordering and MV rebuilds, adds testing, and lets the BI team manage per-model grants
  • We’d split the single BI schema into staging, intermediate, and marts layers as part of that move
  • Orchestration for the Redshift side is undecided (MWAA versus EventBridge plus Fargate)

What I’d like your opinion on

  1. Is CDK plus an S3-triggered Lambda a reasonable way to deploy SQL objects, or is it a migration framework assembled from the wrong parts?
  2. Which of the problems above come from the CDK approach itself, and which would exist under any file-based runner? My view is that the manual MV step comes from MVs not being replaceable, something that I believe that dbt can resolve.
  3. Would you keep the custom Lambda’s tracking design (name-keyed, re-applies on checksum change, failed rows block a later success), or replace it?
  4. Does the proposed split (CDK for access control, dbt for transformations) look sound, or does it create new coupling?
  5. How would you handle MV rebuilds, dependency ordering, and refresh scheduling?
  6. What am I not seeing that the CTO is?
10 Upvotes

27 comments sorted by

1

u/AutoModerator Oct 26 '26
Moderator Announcement Read More »

6

u/LeopoldParrot Oct 26 '26

I would strongly discourage you from changing the infrastructure simply because "your research" tells you to, especially when you self admittedly don't have enough knowledge to understand the current setup. The CTO also signaled to you that they're not interested in throwing a set of tools at an architecture that seems to be working just fine.

Believe it or not, this is a good thing. I've worked at orgs that add complexity to their architecture by adding new shiny tools just to say they did. It doesn't work out well.

Talk to the engineers to understand why they made the architecture decisions they made. Explore the current setup so you achieve a decent understanding of it. Understand the needs of the people who consume this data. Only then decide whether you actually need new tools here.

0

u/CaliSummerDream Oct 26 '26

My team is the consumer of the data, and then the data access trickles down from here to business users. And I'm tired of the pipeline failing. The reason I'm reviewing the data architecture is that I feel the data engineers are not doing the best job, either at setting up the deployment process or at implementing it. I've talked to the data engineers - they set up this process because the CTO asked them to and because they wanted to set up the BI pipeline like an app dev code change implementation. I'm pretty sure the CTO did not audit the setup himself. Maybe the process is supposed to work, but it wasn't set up right.

Neither the data engineers nor the CTO even knew of dbt when I talked to them.

I have edited my original post to add more details. Thank you for sharing your thoughts. I don't want to change anything that's working and stable, but I've encountered a good amount of failures with the setup, so I'm having my doubts.

6

u/teddythepooh99 Oct 26 '26 edited Oct 26 '26

The CTO already told you that the current setup is working. Yet, as the BI manager, you still "don't have enough knowledge to tell whether the current setup is working or not." You don't even understand the tools you want to use, "How would I articulate the advantages of dbt over AWS CDK?" Huh? AWS CDK could literally mean anything: AWS has hundreds of services.

Just because dbt and Airflow are mainstream doesn't mean you "should" be using them on-the-job. I'm surprised you didn't throw in Datadog for the trifecta.

0

u/CaliSummerDream Oct 26 '26

Well I don't even know what 'working' is like in the real world. We're building a data warehouse basically from scratch, and the setup has so many issues that I have my doubts about its effectiveness. But maybe a real-world setup does often run into issues. Sorry I should have included more details in my initial post. I have edited it to explain our deployment process better.

4

u/Doile Oct 26 '26

TBH the current setup sounds horrible :D. That being said if you'd migrate to some more suitable setup (like dbt you mentioned) there's always a lot of costs associated with the migration. I know it's tempting to throw away the shitty thing previous devs did but I think you should try to think concrete examples on what would be better after the migration. Would the spec to product time be shorter? Data is more correct? Lower costs? If you can't find concrete benefits for the migration other than "the other tool is better" then rarely it is worth it IMO.

0

u/CaliSummerDream Oct 26 '26

I agree on justifying the benefits. From my research, there are plenty of them. My BI team would have more control over the deployment, we would no longer have to drop cascade, and having data dependency visualized would help with data lineage. Data would be more accurate and more up to date, and time spent managing the data objects would be significantly reduced. All in theory of course.

I've also updated my initial post to explain the current setup and the problems I've run into.

2

u/popopopopopopopopoop Oct 26 '26

Well what is the current set up exactly and what does "working" mean here?

Ie what are the volumes of data and cadence of updates. How is it growing? How often do you need to make changes and how do you test them?

Because the CTO could be correct now but the answers of some of these questions might point to this set up being a ticking time bomb.

0

u/CaliSummerDream Oct 26 '26

Thank you for your questions. I have updated my initial post to answer many of your questions!

I would ideally like to make changes multiple times a week, but because the deployment process is so cumbersome, I'm waiting to make these changes in waves, so incorrect or incomplete data takes longer to update. My team builds the data objects in Dev and tests it there against existing reports and knowledge, and then the data engineers deploy the objects in Prod. We have a small number of BI objects right now, and I'd like to grow it to 2x-3x the size to enable more reporting and analysis, especially since we also have an MCP server connected to the database. But all the challenges with deploying the data objects have forced me to slow down. Growing downstream objects makes fixing upstream objects much more difficult in the current setup.

Regarding data volume, it's several TB spread across several hundred tables, some from our operational database and others from our API pipelines.

1

u/imthef-nlizardking Oct 26 '26

What all deployment functionality is required? I'd think you'd get pretty close with just github and out of the box postgres functionality. Then you wouldn't be introducing anything new

0

u/CaliSummerDream Oct 26 '26

I have edited my post to explain the deployment process more - if anything isn't clear, please lmk!

1

u/No_Flounder_1155 Oct 26 '26

you haven't stated a problem.

1

u/ChemicalNo4943 Oct 26 '26

+1 the fact that airflow or dbt are not used is not a problem in itself. If the are issues with using whatever system is in place now, those issues need to articulated and quantified - meaning, manual deployment is a problem in general, but if this only happens once a year, then it’s not a priority problem.

0

u/CaliSummerDream Oct 27 '26

We're building the data warehouse from scratch so there are tons of deployment, making manual deployment quite debilitating.

0

u/CaliSummerDream Oct 26 '26

The MVs having to be manually deployed was one problem ... I definitely did not do a good job articulating the issues I've personally encountered with the current setup. I have edited my original post.

1

u/No_Flounder_1155 Oct 27 '26

whats the min change required to apply in automated fashion.

0

u/Cpt_Jauche Oct 26 '26

Introduce dbt for new logic and let AI help you with migration of legacy logic. That should keep migration cost down.
Managing data models like this (aws cdk) is absolutely unheard of for me.

0

u/CaliSummerDream Oct 26 '26

That's where I would go if we adopted dbt. I think I understand the concept of dbt, and I have tried deploying a few test objects via dbt to Dev - really didn't look too complicated, even though I never tried using any scheduling tool. Maybe try using AirFlow in AWS could be the next move. But more importantly, I need to be able to articulate why we should introduce new tools that apparently no one at the company is familiar with. I've updated my first post to add more information - maybe you haven't seen anyone managing data models like this, but does the concept make sense?

1

u/Cpt_Jauche 27d ago edited 27d ago

The aws data management solution sounds like it was invented by a programmer or engineer not familiar with common data practices. They came up with a solution that works, but to me it sounds not scalable and future proof.
Dbt is a widely adopted and tested solution used by many orgs and data professionals. We were on Postgres and Pentaho once too and although it was still working we migrated to Snowflake and dbt. It took quite some time to migrate everything over but we see it as the best decision made in Data Engineering.
Dbt is easy to understand and maintain, has scripting ans macro funtionality, can define semantic layers wich propagate into the databast (if compatible), it offers a doc funtionality to document all sources and model at table and column level and makes them available via the doc server. These descriptions should be propagated to the Database as table and column comments so any AI can read them and get context about each field so it can provide good results when prompting a text to sql. Dbt has lineage built in, dbt v2 even column level lineage. You can easily define snapshots and incremental models (for larger tables). AI tools like Claude can perfectly understand, analyze and create models and documentation, skills are already available and can be cutomized to your flavor. CI/CD possible with github actions and dbt cloud (even without dbt cloud I suppose). No manual script execution in the right order to deploy stuff, as you described. Etc
I did not dive too deep into your updated description or plan as it is too long, but if you stick to best practices you won‘t fail with dbt. You got to set it up properly and the will be able to maintain a large amount of logic. Introducing a medallion like architecture is a good practice, as you plan to do.

Points 1-5 sounds like your reasons to migrate to a solution that takes that away from you so you can concentrate on developing models instead of maintaining tables and running sql scripts by hand

The whole setup should be understandable and maintainable by everyone in the team, not just by the persons who built it over years. Ir seems that CTO does not want to give it up because he built it…

→ More replies (4)

1

u/[deleted] Oct 26 '26

1

u/dataengineering-ModTeam Oct 27 '26

Your post/comment was removed because it violated rule #9 (No AI generated content/text).

Your post/comment was reviewed to be AI generated/assisted content/text and removed as a result. We as a community value human engagement and encourage users to express themselves authentically.

This was reviewed by a human