[{"data":1,"prerenderedAt":3146},["ShallowReactive",2],{"article-alternates":3,"article-\u002Fde\u002Fdata\u002Fcohort-table-architecture-production-scaling":13},{"i18nKey":4,"paths":5},"data-007-2026-06",{"de":6,"en":7,"es":8,"fr":9,"it":10,"ru":11,"tr":12},"\u002Fde\u002Fdata\u002Fcohort-table-architecture-production-scaling","\u002Fen\u002Fdata\u002Fcohort-table-architecture-scaling-retention-analysis-production","\u002Fes\u002Fdata\u002Farquitectura-tabla-cohort","\u002Ffr\u002Fdata\u002Fcohort-table-architecture-production-scaling","\u002Fit\u002Fdata\u002Farchitettura-tabella-cohort","\u002Fru\u002Fdata\u002Fcohort-tablitsa-arkhitektura-masshtabirovanie-analiza-uderzhaniia-v-produkcii","\u002Ftr\u002Fdata\u002Fcohort-tablo-mimarisi-retention-analizinin-productionda-olceklenmesi",{"_path":6,"_dir":14,"_draft":15,"_partial":15,"_locale":16,"title":17,"description":18,"publishedAt":19,"modifiedAt":19,"category":14,"i18nKey":4,"tags":20,"readingTime":26,"author":27,"body":28,"_type":3140,"_id":3141,"_source":3142,"_file":3143,"_stem":3144,"_extension":3145},"data",false,"","Cohort Table Architecture: Scaling Retention Analysis in Production","Architecture design using materialized views, partitioning, and query cost optimization to query 100M+ daily events in cohort tables in 5 seconds.","2026-06-09",[21,22,23,24,25],"cohort-analysis","bigquery","materialized-views","query-optimization","retention-engineering",8,"Roibase",{"type":29,"children":30,"toc":3131},"root",[31,39,46,83,452,471,478,491,1283,1288,1294,1306,1695,1700,1708,1834,1852,1858,1863,1881,1978,2003,2016,2040,2046,2083,2661,2666,2672,2685,3001,3014,3022,3120,3125],{"type":32,"tag":33,"props":34,"children":35},"element","p",{},[36],{"type":37,"value":38},"text","When moving retention metrics to a real-time dashboard, the first shock comes in query costs. A basic cohort query — \"Of users who signed up on January 1st, how many were active on day 7?\" — scans 200GB of data when written naively, takes 18 seconds to execute, and costs $4. For a team with 500 daily dashboard visits, this math becomes $60,000 per month. The problem isn't your analytical capability—it's table architecture. Moving cohort analysis to production requires storing cohort snapshots, not raw event data.",{"type":32,"tag":40,"props":41,"children":43},"h2",{"id":42},"naive-cohort-query-why-it-doesnt-scale",[44],{"type":37,"value":45},"Naive Cohort Query: Why It Doesn't Scale",{"type":32,"tag":33,"props":47,"children":48},{},[49,51,58,60,66,68,74,76,81],{"type":37,"value":50},"A classic cohort query joins three tables: ",{"type":32,"tag":52,"props":53,"children":55},"code",{"className":54},[],[56],{"type":37,"value":57},"users",{"type":37,"value":59},", ",{"type":32,"tag":52,"props":61,"children":63},{"className":62},[],[64],{"type":37,"value":65},"events",{"type":37,"value":67},", and ",{"type":32,"tag":52,"props":69,"children":71},{"className":70},[],[72],{"type":37,"value":73},"cohort_definitions",{"type":37,"value":75},". With each query, the ",{"type":32,"tag":52,"props":77,"children":79},{"className":78},[],[80],{"type":37,"value":65},{"type":37,"value":82}," table gets a full scan without partition filtering. At 100M daily events, this approach is unsustainable.",{"type":32,"tag":84,"props":85,"children":89},"pre",{"className":86,"code":87,"language":88,"meta":16,"style":16},"language-sql shiki shiki-themes github-dark","-- ❌ Anti-pattern: Scanning all events every time\nSELECT \n  DATE_TRUNC(u.created_at, DAY) AS cohort_date,\n  DATE_DIFF(e.event_date, u.created_at, DAY) AS day_n,\n  COUNT(DISTINCT u.user_id) AS retained_users\nFROM users u\nJOIN events e ON u.user_id = e.user_id\nWHERE u.created_at >= '2026-01-01'\n  AND e.event_name = 'session_start'\nGROUP BY 1, 2\nORDER BY 1, 2;\n","sql",[90],{"type":32,"tag":52,"props":91,"children":92},{"__ignoreMap":16},[93,105,121,170,230,276,290,340,371,402,425],{"type":32,"tag":94,"props":95,"children":98},"span",{"class":96,"line":97},"line",1,[99],{"type":32,"tag":94,"props":100,"children":102},{"style":101},"--shiki-default:#6A737D",[103],{"type":37,"value":104},"-- ❌ Anti-pattern: Scanning all events every time\n",{"type":32,"tag":94,"props":106,"children":108},{"class":96,"line":107},2,[109,115],{"type":32,"tag":94,"props":110,"children":112},{"style":111},"--shiki-default:#F97583",[113],{"type":37,"value":114},"SELECT",{"type":32,"tag":94,"props":116,"children":118},{"style":117},"--shiki-default:#E1E4E8",[119],{"type":37,"value":120}," \n",{"type":32,"tag":94,"props":122,"children":124},{"class":96,"line":123},3,[125,130,136,141,146,150,155,160,165],{"type":32,"tag":94,"props":126,"children":127},{"style":117},[128],{"type":37,"value":129},"  DATE_TRUNC(",{"type":32,"tag":94,"props":131,"children":133},{"style":132},"--shiki-default:#79B8FF",[134],{"type":37,"value":135},"u",{"type":32,"tag":94,"props":137,"children":138},{"style":117},[139],{"type":37,"value":140},".",{"type":32,"tag":94,"props":142,"children":143},{"style":132},[144],{"type":37,"value":145},"created_at",{"type":32,"tag":94,"props":147,"children":148},{"style":117},[149],{"type":37,"value":59},{"type":32,"tag":94,"props":151,"children":152},{"style":111},[153],{"type":37,"value":154},"DAY",{"type":32,"tag":94,"props":156,"children":157},{"style":117},[158],{"type":37,"value":159},") ",{"type":32,"tag":94,"props":161,"children":162},{"style":111},[163],{"type":37,"value":164},"AS",{"type":32,"tag":94,"props":166,"children":167},{"style":117},[168],{"type":37,"value":169}," cohort_date,\n",{"type":32,"tag":94,"props":171,"children":173},{"class":96,"line":172},4,[174,179,184,188,193,197,201,205,209,213,217,221,225],{"type":32,"tag":94,"props":175,"children":176},{"style":117},[177],{"type":37,"value":178},"  DATE_DIFF(",{"type":32,"tag":94,"props":180,"children":181},{"style":132},[182],{"type":37,"value":183},"e",{"type":32,"tag":94,"props":185,"children":186},{"style":117},[187],{"type":37,"value":140},{"type":32,"tag":94,"props":189,"children":190},{"style":132},[191],{"type":37,"value":192},"event_date",{"type":32,"tag":94,"props":194,"children":195},{"style":117},[196],{"type":37,"value":59},{"type":32,"tag":94,"props":198,"children":199},{"style":132},[200],{"type":37,"value":135},{"type":32,"tag":94,"props":202,"children":203},{"style":117},[204],{"type":37,"value":140},{"type":32,"tag":94,"props":206,"children":207},{"style":132},[208],{"type":37,"value":145},{"type":32,"tag":94,"props":210,"children":211},{"style":117},[212],{"type":37,"value":59},{"type":32,"tag":94,"props":214,"children":215},{"style":111},[216],{"type":37,"value":154},{"type":32,"tag":94,"props":218,"children":219},{"style":117},[220],{"type":37,"value":159},{"type":32,"tag":94,"props":222,"children":223},{"style":111},[224],{"type":37,"value":164},{"type":32,"tag":94,"props":226,"children":227},{"style":117},[228],{"type":37,"value":229}," day_n,\n",{"type":32,"tag":94,"props":231,"children":233},{"class":96,"line":232},5,[234,239,244,249,254,258,263,267,271],{"type":32,"tag":94,"props":235,"children":236},{"style":132},[237],{"type":37,"value":238},"  COUNT",{"type":32,"tag":94,"props":240,"children":241},{"style":117},[242],{"type":37,"value":243},"(",{"type":32,"tag":94,"props":245,"children":246},{"style":111},[247],{"type":37,"value":248},"DISTINCT",{"type":32,"tag":94,"props":250,"children":251},{"style":132},[252],{"type":37,"value":253}," u",{"type":32,"tag":94,"props":255,"children":256},{"style":117},[257],{"type":37,"value":140},{"type":32,"tag":94,"props":259,"children":260},{"style":132},[261],{"type":37,"value":262},"user_id",{"type":32,"tag":94,"props":264,"children":265},{"style":117},[266],{"type":37,"value":159},{"type":32,"tag":94,"props":268,"children":269},{"style":111},[270],{"type":37,"value":164},{"type":32,"tag":94,"props":272,"children":273},{"style":117},[274],{"type":37,"value":275}," retained_users\n",{"type":32,"tag":94,"props":277,"children":279},{"class":96,"line":278},6,[280,285],{"type":32,"tag":94,"props":281,"children":282},{"style":111},[283],{"type":37,"value":284},"FROM",{"type":32,"tag":94,"props":286,"children":287},{"style":117},[288],{"type":37,"value":289}," users u\n",{"type":32,"tag":94,"props":291,"children":293},{"class":96,"line":292},7,[294,299,304,309,313,317,321,326,331,335],{"type":32,"tag":94,"props":295,"children":296},{"style":111},[297],{"type":37,"value":298},"JOIN",{"type":32,"tag":94,"props":300,"children":301},{"style":117},[302],{"type":37,"value":303}," events e ",{"type":32,"tag":94,"props":305,"children":306},{"style":111},[307],{"type":37,"value":308},"ON",{"type":32,"tag":94,"props":310,"children":311},{"style":132},[312],{"type":37,"value":253},{"type":32,"tag":94,"props":314,"children":315},{"style":117},[316],{"type":37,"value":140},{"type":32,"tag":94,"props":318,"children":319},{"style":132},[320],{"type":37,"value":262},{"type":32,"tag":94,"props":322,"children":323},{"style":111},[324],{"type":37,"value":325}," =",{"type":32,"tag":94,"props":327,"children":328},{"style":132},[329],{"type":37,"value":330}," e",{"type":32,"tag":94,"props":332,"children":333},{"style":117},[334],{"type":37,"value":140},{"type":32,"tag":94,"props":336,"children":337},{"style":132},[338],{"type":37,"value":339},"user_id\n",{"type":32,"tag":94,"props":341,"children":342},{"class":96,"line":26},[343,348,352,356,360,365],{"type":32,"tag":94,"props":344,"children":345},{"style":111},[346],{"type":37,"value":347},"WHERE",{"type":32,"tag":94,"props":349,"children":350},{"style":132},[351],{"type":37,"value":253},{"type":32,"tag":94,"props":353,"children":354},{"style":117},[355],{"type":37,"value":140},{"type":32,"tag":94,"props":357,"children":358},{"style":132},[359],{"type":37,"value":145},{"type":32,"tag":94,"props":361,"children":362},{"style":111},[363],{"type":37,"value":364}," >=",{"type":32,"tag":94,"props":366,"children":368},{"style":367},"--shiki-default:#9ECBFF",[369],{"type":37,"value":370}," '2026-01-01'\n",{"type":32,"tag":94,"props":372,"children":374},{"class":96,"line":373},9,[375,380,384,388,393,397],{"type":32,"tag":94,"props":376,"children":377},{"style":111},[378],{"type":37,"value":379},"  AND",{"type":32,"tag":94,"props":381,"children":382},{"style":132},[383],{"type":37,"value":330},{"type":32,"tag":94,"props":385,"children":386},{"style":117},[387],{"type":37,"value":140},{"type":32,"tag":94,"props":389,"children":390},{"style":132},[391],{"type":37,"value":392},"event_name",{"type":32,"tag":94,"props":394,"children":395},{"style":111},[396],{"type":37,"value":325},{"type":32,"tag":94,"props":398,"children":399},{"style":367},[400],{"type":37,"value":401}," 'session_start'\n",{"type":32,"tag":94,"props":403,"children":405},{"class":96,"line":404},10,[406,411,416,420],{"type":32,"tag":94,"props":407,"children":408},{"style":111},[409],{"type":37,"value":410},"GROUP BY",{"type":32,"tag":94,"props":412,"children":413},{"style":132},[414],{"type":37,"value":415}," 1",{"type":32,"tag":94,"props":417,"children":418},{"style":117},[419],{"type":37,"value":59},{"type":32,"tag":94,"props":421,"children":422},{"style":132},[423],{"type":37,"value":424},"2\n",{"type":32,"tag":94,"props":426,"children":428},{"class":96,"line":427},11,[429,434,438,442,447],{"type":32,"tag":94,"props":430,"children":431},{"style":111},[432],{"type":37,"value":433},"ORDER BY",{"type":32,"tag":94,"props":435,"children":436},{"style":132},[437],{"type":37,"value":415},{"type":32,"tag":94,"props":439,"children":440},{"style":117},[441],{"type":37,"value":59},{"type":32,"tag":94,"props":443,"children":444},{"style":132},[445],{"type":37,"value":446},"2",{"type":32,"tag":94,"props":448,"children":449},{"style":117},[450],{"type":37,"value":451},";\n",{"type":32,"tag":33,"props":453,"children":454},{},[455,457,463,465,470],{"type":37,"value":456},"This query scans 480GB for 6 months of data, takes 12 seconds due to BigQuery slot consumption, and costs $2.40 (on-demand pricing: $5\u002FTB). When you multiply the same cohort across 20 different metrics (revenue, session count, conversion rate), costs reach $48. If the dashboard refreshes 100 times daily, monthly cost hits $144,000. To scale this for production, two strategies emerge: ",{"type":32,"tag":458,"props":459,"children":460},"strong",{},[461],{"type":37,"value":462},"incremental materialization",{"type":37,"value":464}," and ",{"type":32,"tag":458,"props":466,"children":467},{},[468],{"type":37,"value":469},"pre-aggregated cohort snapshots",{"type":37,"value":140},{"type":32,"tag":472,"props":473,"children":475},"h3",{"id":474},"incremental-materialization-event-to-cohort-pipeline-with-dbt",[476],{"type":37,"value":477},"Incremental Materialization: Event-to-Cohort Pipeline with dbt",{"type":32,"tag":33,"props":479,"children":480},{},[481,483,489],{"type":37,"value":482},"Instead of calculating cohorts on every query, update an accumulated table with daily batches. dbt's ",{"type":32,"tag":52,"props":484,"children":486},{"className":485},[],[487],{"type":37,"value":488},"incremental",{"type":37,"value":490}," strategy lets you add only the new day's events to the existing cohort table.",{"type":32,"tag":84,"props":492,"children":494},{"className":86,"code":493,"language":88,"meta":16,"style":16},"-- models\u002Fcohort_retention_daily.sql\n{{\n  config(\n    materialized='incremental',\n    partition_by={'field': 'cohort_date', 'data_type': 'date'},\n    cluster_by=['day_n', 'metric_name'],\n    unique_key='cohort_date || day_n || metric_name'\n  )\n}}\n\nWITH new_events AS (\n  SELECT \n    u.user_id,\n    DATE_TRUNC(u.created_at, DAY) AS cohort_date,\n    DATE_DIFF(e.event_date, u.created_at, DAY) AS day_n,\n    e.event_name,\n    e.revenue_usd\n  FROM {{ ref('events') }} e\n  JOIN {{ ref('users') }} u ON e.user_id = u.user_id\n  {% if is_incremental() %}\n  WHERE e.event_date = CURRENT_DATE() - 1  -- Only yesterday's data\n  {% endif %}\n)\nSELECT\n  cohort_date,\n  day_n,\n  'active_users' AS metric_name,\n  COUNT(DISTINCT user_id) AS metric_value\nFROM new_events\nWHERE event_name = 'session_start'\nGROUP BY 1, 2, 3\n\nUNION ALL\n\nSELECT\n  cohort_date,\n  day_n,\n  'revenue_per_cohort' AS metric_name,\n  SUM(revenue_usd) AS metric_value\nFROM new_events\nGROUP BY 1, 2, 3;\n",[495],{"type":32,"tag":52,"props":496,"children":497},{"__ignoreMap":16},[498,506,514,522,545,600,617,634,642,650,659,681,694,715,756,813,834,851,875,930,949,993,1002,1011,1020,1029,1038,1057,1087,1100,1121,1150,1158,1167,1175,1183,1191,1199,1216,1238,1250],{"type":32,"tag":94,"props":499,"children":500},{"class":96,"line":97},[501],{"type":32,"tag":94,"props":502,"children":503},{"style":101},[504],{"type":37,"value":505},"-- models\u002Fcohort_retention_daily.sql\n",{"type":32,"tag":94,"props":507,"children":508},{"class":96,"line":107},[509],{"type":32,"tag":94,"props":510,"children":511},{"style":117},[512],{"type":37,"value":513},"{{\n",{"type":32,"tag":94,"props":515,"children":516},{"class":96,"line":123},[517],{"type":32,"tag":94,"props":518,"children":519},{"style":117},[520],{"type":37,"value":521},"  config(\n",{"type":32,"tag":94,"props":523,"children":524},{"class":96,"line":172},[525,530,535,540],{"type":32,"tag":94,"props":526,"children":527},{"style":117},[528],{"type":37,"value":529},"    materialized",{"type":32,"tag":94,"props":531,"children":532},{"style":111},[533],{"type":37,"value":534},"=",{"type":32,"tag":94,"props":536,"children":537},{"style":367},[538],{"type":37,"value":539},"'incremental'",{"type":32,"tag":94,"props":541,"children":542},{"style":117},[543],{"type":37,"value":544},",\n",{"type":32,"tag":94,"props":546,"children":547},{"class":96,"line":232},[548,553,557,562,567,572,577,581,586,590,595],{"type":32,"tag":94,"props":549,"children":550},{"style":117},[551],{"type":37,"value":552},"    partition_by",{"type":32,"tag":94,"props":554,"children":555},{"style":111},[556],{"type":37,"value":534},{"type":32,"tag":94,"props":558,"children":559},{"style":117},[560],{"type":37,"value":561},"{",{"type":32,"tag":94,"props":563,"children":564},{"style":367},[565],{"type":37,"value":566},"'field'",{"type":32,"tag":94,"props":568,"children":569},{"style":117},[570],{"type":37,"value":571},": ",{"type":32,"tag":94,"props":573,"children":574},{"style":367},[575],{"type":37,"value":576},"'cohort_date'",{"type":32,"tag":94,"props":578,"children":579},{"style":117},[580],{"type":37,"value":59},{"type":32,"tag":94,"props":582,"children":583},{"style":367},[584],{"type":37,"value":585},"'data_type'",{"type":32,"tag":94,"props":587,"children":588},{"style":117},[589],{"type":37,"value":571},{"type":32,"tag":94,"props":591,"children":592},{"style":367},[593],{"type":37,"value":594},"'date'",{"type":32,"tag":94,"props":596,"children":597},{"style":117},[598],{"type":37,"value":599},"},\n",{"type":32,"tag":94,"props":601,"children":602},{"class":96,"line":278},[603,608,612],{"type":32,"tag":94,"props":604,"children":605},{"style":117},[606],{"type":37,"value":607},"    cluster_by",{"type":32,"tag":94,"props":609,"children":610},{"style":111},[611],{"type":37,"value":534},{"type":32,"tag":94,"props":613,"children":614},{"style":117},[615],{"type":37,"value":616},"['day_n', 'metric_name'],\n",{"type":32,"tag":94,"props":618,"children":619},{"class":96,"line":292},[620,625,629],{"type":32,"tag":94,"props":621,"children":622},{"style":117},[623],{"type":37,"value":624},"    unique_key",{"type":32,"tag":94,"props":626,"children":627},{"style":111},[628],{"type":37,"value":534},{"type":32,"tag":94,"props":630,"children":631},{"style":367},[632],{"type":37,"value":633},"'cohort_date || day_n || metric_name'\n",{"type":32,"tag":94,"props":635,"children":636},{"class":96,"line":26},[637],{"type":32,"tag":94,"props":638,"children":639},{"style":117},[640],{"type":37,"value":641},"  )\n",{"type":32,"tag":94,"props":643,"children":644},{"class":96,"line":373},[645],{"type":32,"tag":94,"props":646,"children":647},{"style":117},[648],{"type":37,"value":649},"}}\n",{"type":32,"tag":94,"props":651,"children":652},{"class":96,"line":404},[653],{"type":32,"tag":94,"props":654,"children":656},{"emptyLinePlaceholder":655},true,[657],{"type":37,"value":658},"\n",{"type":32,"tag":94,"props":660,"children":661},{"class":96,"line":427},[662,667,672,676],{"type":32,"tag":94,"props":663,"children":664},{"style":111},[665],{"type":37,"value":666},"WITH",{"type":32,"tag":94,"props":668,"children":669},{"style":117},[670],{"type":37,"value":671}," new_events ",{"type":32,"tag":94,"props":673,"children":674},{"style":111},[675],{"type":37,"value":164},{"type":32,"tag":94,"props":677,"children":678},{"style":117},[679],{"type":37,"value":680}," (\n",{"type":32,"tag":94,"props":682,"children":684},{"class":96,"line":683},12,[685,690],{"type":32,"tag":94,"props":686,"children":687},{"style":111},[688],{"type":37,"value":689},"  SELECT",{"type":32,"tag":94,"props":691,"children":692},{"style":117},[693],{"type":37,"value":120},{"type":32,"tag":94,"props":695,"children":697},{"class":96,"line":696},13,[698,703,707,711],{"type":32,"tag":94,"props":699,"children":700},{"style":132},[701],{"type":37,"value":702},"    u",{"type":32,"tag":94,"props":704,"children":705},{"style":117},[706],{"type":37,"value":140},{"type":32,"tag":94,"props":708,"children":709},{"style":132},[710],{"type":37,"value":262},{"type":32,"tag":94,"props":712,"children":713},{"style":117},[714],{"type":37,"value":544},{"type":32,"tag":94,"props":716,"children":718},{"class":96,"line":717},14,[719,724,728,732,736,740,744,748,752],{"type":32,"tag":94,"props":720,"children":721},{"style":117},[722],{"type":37,"value":723},"    DATE_TRUNC(",{"type":32,"tag":94,"props":725,"children":726},{"style":132},[727],{"type":37,"value":135},{"type":32,"tag":94,"props":729,"children":730},{"style":117},[731],{"type":37,"value":140},{"type":32,"tag":94,"props":733,"children":734},{"style":132},[735],{"type":37,"value":145},{"type":32,"tag":94,"props":737,"children":738},{"style":117},[739],{"type":37,"value":59},{"type":32,"tag":94,"props":741,"children":742},{"style":111},[743],{"type":37,"value":154},{"type":32,"tag":94,"props":745,"children":746},{"style":117},[747],{"type":37,"value":159},{"type":32,"tag":94,"props":749,"children":750},{"style":111},[751],{"type":37,"value":164},{"type":32,"tag":94,"props":753,"children":754},{"style":117},[755],{"type":37,"value":169},{"type":32,"tag":94,"props":757,"children":759},{"class":96,"line":758},15,[760,765,769,773,777,781,785,789,793,797,801,805,809],{"type":32,"tag":94,"props":761,"children":762},{"style":117},[763],{"type":37,"value":764},"    DATE_DIFF(",{"type":32,"tag":94,"props":766,"children":767},{"style":132},[768],{"type":37,"value":183},{"type":32,"tag":94,"props":770,"children":771},{"style":117},[772],{"type":37,"value":140},{"type":32,"tag":94,"props":774,"children":775},{"style":132},[776],{"type":37,"value":192},{"type":32,"tag":94,"props":778,"children":779},{"style":117},[780],{"type":37,"value":59},{"type":32,"tag":94,"props":782,"children":783},{"style":132},[784],{"type":37,"value":135},{"type":32,"tag":94,"props":786,"children":787},{"style":117},[788],{"type":37,"value":140},{"type":32,"tag":94,"props":790,"children":791},{"style":132},[792],{"type":37,"value":145},{"type":32,"tag":94,"props":794,"children":795},{"style":117},[796],{"type":37,"value":59},{"type":32,"tag":94,"props":798,"children":799},{"style":111},[800],{"type":37,"value":154},{"type":32,"tag":94,"props":802,"children":803},{"style":117},[804],{"type":37,"value":159},{"type":32,"tag":94,"props":806,"children":807},{"style":111},[808],{"type":37,"value":164},{"type":32,"tag":94,"props":810,"children":811},{"style":117},[812],{"type":37,"value":229},{"type":32,"tag":94,"props":814,"children":816},{"class":96,"line":815},16,[817,822,826,830],{"type":32,"tag":94,"props":818,"children":819},{"style":132},[820],{"type":37,"value":821},"    e",{"type":32,"tag":94,"props":823,"children":824},{"style":117},[825],{"type":37,"value":140},{"type":32,"tag":94,"props":827,"children":828},{"style":132},[829],{"type":37,"value":392},{"type":32,"tag":94,"props":831,"children":832},{"style":117},[833],{"type":37,"value":544},{"type":32,"tag":94,"props":835,"children":837},{"class":96,"line":836},17,[838,842,846],{"type":32,"tag":94,"props":839,"children":840},{"style":132},[841],{"type":37,"value":821},{"type":32,"tag":94,"props":843,"children":844},{"style":117},[845],{"type":37,"value":140},{"type":32,"tag":94,"props":847,"children":848},{"style":132},[849],{"type":37,"value":850},"revenue_usd\n",{"type":32,"tag":94,"props":852,"children":854},{"class":96,"line":853},18,[855,860,865,870],{"type":32,"tag":94,"props":856,"children":857},{"style":111},[858],{"type":37,"value":859},"  FROM",{"type":32,"tag":94,"props":861,"children":862},{"style":117},[863],{"type":37,"value":864}," {{ ref(",{"type":32,"tag":94,"props":866,"children":867},{"style":367},[868],{"type":37,"value":869},"'events'",{"type":32,"tag":94,"props":871,"children":872},{"style":117},[873],{"type":37,"value":874},") }} e\n",{"type":32,"tag":94,"props":876,"children":878},{"class":96,"line":877},19,[879,884,888,893,898,902,906,910,914,918,922,926],{"type":32,"tag":94,"props":880,"children":881},{"style":111},[882],{"type":37,"value":883},"  JOIN",{"type":32,"tag":94,"props":885,"children":886},{"style":117},[887],{"type":37,"value":864},{"type":32,"tag":94,"props":889,"children":890},{"style":367},[891],{"type":37,"value":892},"'users'",{"type":32,"tag":94,"props":894,"children":895},{"style":117},[896],{"type":37,"value":897},") }} u ",{"type":32,"tag":94,"props":899,"children":900},{"style":111},[901],{"type":37,"value":308},{"type":32,"tag":94,"props":903,"children":904},{"style":132},[905],{"type":37,"value":330},{"type":32,"tag":94,"props":907,"children":908},{"style":117},[909],{"type":37,"value":140},{"type":32,"tag":94,"props":911,"children":912},{"style":132},[913],{"type":37,"value":262},{"type":32,"tag":94,"props":915,"children":916},{"style":111},[917],{"type":37,"value":325},{"type":32,"tag":94,"props":919,"children":920},{"style":132},[921],{"type":37,"value":253},{"type":32,"tag":94,"props":923,"children":924},{"style":117},[925],{"type":37,"value":140},{"type":32,"tag":94,"props":927,"children":928},{"style":132},[929],{"type":37,"value":339},{"type":32,"tag":94,"props":931,"children":933},{"class":96,"line":932},20,[934,939,944],{"type":32,"tag":94,"props":935,"children":936},{"style":117},[937],{"type":37,"value":938},"  {% ",{"type":32,"tag":94,"props":940,"children":941},{"style":111},[942],{"type":37,"value":943},"if",{"type":32,"tag":94,"props":945,"children":946},{"style":117},[947],{"type":37,"value":948}," is_incremental() %}\n",{"type":32,"tag":94,"props":950,"children":952},{"class":96,"line":951},21,[953,958,962,966,970,974,979,984,988],{"type":32,"tag":94,"props":954,"children":955},{"style":111},[956],{"type":37,"value":957},"  WHERE",{"type":32,"tag":94,"props":959,"children":960},{"style":132},[961],{"type":37,"value":330},{"type":32,"tag":94,"props":963,"children":964},{"style":117},[965],{"type":37,"value":140},{"type":32,"tag":94,"props":967,"children":968},{"style":132},[969],{"type":37,"value":192},{"type":32,"tag":94,"props":971,"children":972},{"style":111},[973],{"type":37,"value":325},{"type":32,"tag":94,"props":975,"children":976},{"style":117},[977],{"type":37,"value":978}," CURRENT_DATE() ",{"type":32,"tag":94,"props":980,"children":981},{"style":111},[982],{"type":37,"value":983},"-",{"type":32,"tag":94,"props":985,"children":986},{"style":132},[987],{"type":37,"value":415},{"type":32,"tag":94,"props":989,"children":990},{"style":101},[991],{"type":37,"value":992},"  -- Only yesterday's data\n",{"type":32,"tag":94,"props":994,"children":996},{"class":96,"line":995},22,[997],{"type":32,"tag":94,"props":998,"children":999},{"style":117},[1000],{"type":37,"value":1001},"  {% endif %}\n",{"type":32,"tag":94,"props":1003,"children":1005},{"class":96,"line":1004},23,[1006],{"type":32,"tag":94,"props":1007,"children":1008},{"style":117},[1009],{"type":37,"value":1010},")\n",{"type":32,"tag":94,"props":1012,"children":1014},{"class":96,"line":1013},24,[1015],{"type":32,"tag":94,"props":1016,"children":1017},{"style":111},[1018],{"type":37,"value":1019},"SELECT\n",{"type":32,"tag":94,"props":1021,"children":1023},{"class":96,"line":1022},25,[1024],{"type":32,"tag":94,"props":1025,"children":1026},{"style":117},[1027],{"type":37,"value":1028},"  cohort_date,\n",{"type":32,"tag":94,"props":1030,"children":1032},{"class":96,"line":1031},26,[1033],{"type":32,"tag":94,"props":1034,"children":1035},{"style":117},[1036],{"type":37,"value":1037},"  day_n,\n",{"type":32,"tag":94,"props":1039,"children":1041},{"class":96,"line":1040},27,[1042,1047,1052],{"type":32,"tag":94,"props":1043,"children":1044},{"style":367},[1045],{"type":37,"value":1046},"  'active_users'",{"type":32,"tag":94,"props":1048,"children":1049},{"style":111},[1050],{"type":37,"value":1051}," AS",{"type":32,"tag":94,"props":1053,"children":1054},{"style":117},[1055],{"type":37,"value":1056}," metric_name,\n",{"type":32,"tag":94,"props":1058,"children":1060},{"class":96,"line":1059},28,[1061,1065,1069,1073,1078,1082],{"type":32,"tag":94,"props":1062,"children":1063},{"style":132},[1064],{"type":37,"value":238},{"type":32,"tag":94,"props":1066,"children":1067},{"style":117},[1068],{"type":37,"value":243},{"type":32,"tag":94,"props":1070,"children":1071},{"style":111},[1072],{"type":37,"value":248},{"type":32,"tag":94,"props":1074,"children":1075},{"style":117},[1076],{"type":37,"value":1077}," user_id) ",{"type":32,"tag":94,"props":1079,"children":1080},{"style":111},[1081],{"type":37,"value":164},{"type":32,"tag":94,"props":1083,"children":1084},{"style":117},[1085],{"type":37,"value":1086}," metric_value\n",{"type":32,"tag":94,"props":1088,"children":1090},{"class":96,"line":1089},29,[1091,1095],{"type":32,"tag":94,"props":1092,"children":1093},{"style":111},[1094],{"type":37,"value":284},{"type":32,"tag":94,"props":1096,"children":1097},{"style":117},[1098],{"type":37,"value":1099}," new_events\n",{"type":32,"tag":94,"props":1101,"children":1103},{"class":96,"line":1102},30,[1104,1108,1113,1117],{"type":32,"tag":94,"props":1105,"children":1106},{"style":111},[1107],{"type":37,"value":347},{"type":32,"tag":94,"props":1109,"children":1110},{"style":117},[1111],{"type":37,"value":1112}," event_name ",{"type":32,"tag":94,"props":1114,"children":1115},{"style":111},[1116],{"type":37,"value":534},{"type":32,"tag":94,"props":1118,"children":1119},{"style":367},[1120],{"type":37,"value":401},{"type":32,"tag":94,"props":1122,"children":1124},{"class":96,"line":1123},31,[1125,1129,1133,1137,1141,1145],{"type":32,"tag":94,"props":1126,"children":1127},{"style":111},[1128],{"type":37,"value":410},{"type":32,"tag":94,"props":1130,"children":1131},{"style":132},[1132],{"type":37,"value":415},{"type":32,"tag":94,"props":1134,"children":1135},{"style":117},[1136],{"type":37,"value":59},{"type":32,"tag":94,"props":1138,"children":1139},{"style":132},[1140],{"type":37,"value":446},{"type":32,"tag":94,"props":1142,"children":1143},{"style":117},[1144],{"type":37,"value":59},{"type":32,"tag":94,"props":1146,"children":1147},{"style":132},[1148],{"type":37,"value":1149},"3\n",{"type":32,"tag":94,"props":1151,"children":1153},{"class":96,"line":1152},32,[1154],{"type":32,"tag":94,"props":1155,"children":1156},{"emptyLinePlaceholder":655},[1157],{"type":37,"value":658},{"type":32,"tag":94,"props":1159,"children":1161},{"class":96,"line":1160},33,[1162],{"type":32,"tag":94,"props":1163,"children":1164},{"style":111},[1165],{"type":37,"value":1166},"UNION ALL\n",{"type":32,"tag":94,"props":1168,"children":1170},{"class":96,"line":1169},34,[1171],{"type":32,"tag":94,"props":1172,"children":1173},{"emptyLinePlaceholder":655},[1174],{"type":37,"value":658},{"type":32,"tag":94,"props":1176,"children":1178},{"class":96,"line":1177},35,[1179],{"type":32,"tag":94,"props":1180,"children":1181},{"style":111},[1182],{"type":37,"value":1019},{"type":32,"tag":94,"props":1184,"children":1186},{"class":96,"line":1185},36,[1187],{"type":32,"tag":94,"props":1188,"children":1189},{"style":117},[1190],{"type":37,"value":1028},{"type":32,"tag":94,"props":1192,"children":1194},{"class":96,"line":1193},37,[1195],{"type":32,"tag":94,"props":1196,"children":1197},{"style":117},[1198],{"type":37,"value":1037},{"type":32,"tag":94,"props":1200,"children":1202},{"class":96,"line":1201},38,[1203,1208,1212],{"type":32,"tag":94,"props":1204,"children":1205},{"style":367},[1206],{"type":37,"value":1207},"  'revenue_per_cohort'",{"type":32,"tag":94,"props":1209,"children":1210},{"style":111},[1211],{"type":37,"value":1051},{"type":32,"tag":94,"props":1213,"children":1214},{"style":117},[1215],{"type":37,"value":1056},{"type":32,"tag":94,"props":1217,"children":1219},{"class":96,"line":1218},39,[1220,1225,1230,1234],{"type":32,"tag":94,"props":1221,"children":1222},{"style":132},[1223],{"type":37,"value":1224},"  SUM",{"type":32,"tag":94,"props":1226,"children":1227},{"style":117},[1228],{"type":37,"value":1229},"(revenue_usd) ",{"type":32,"tag":94,"props":1231,"children":1232},{"style":111},[1233],{"type":37,"value":164},{"type":32,"tag":94,"props":1235,"children":1236},{"style":117},[1237],{"type":37,"value":1086},{"type":32,"tag":94,"props":1239,"children":1241},{"class":96,"line":1240},40,[1242,1246],{"type":32,"tag":94,"props":1243,"children":1244},{"style":111},[1245],{"type":37,"value":284},{"type":32,"tag":94,"props":1247,"children":1248},{"style":117},[1249],{"type":37,"value":1099},{"type":32,"tag":94,"props":1251,"children":1253},{"class":96,"line":1252},41,[1254,1258,1262,1266,1270,1274,1279],{"type":32,"tag":94,"props":1255,"children":1256},{"style":111},[1257],{"type":37,"value":410},{"type":32,"tag":94,"props":1259,"children":1260},{"style":132},[1261],{"type":37,"value":415},{"type":32,"tag":94,"props":1263,"children":1264},{"style":117},[1265],{"type":37,"value":59},{"type":32,"tag":94,"props":1267,"children":1268},{"style":132},[1269],{"type":37,"value":446},{"type":32,"tag":94,"props":1271,"children":1272},{"style":117},[1273],{"type":37,"value":59},{"type":32,"tag":94,"props":1275,"children":1276},{"style":132},[1277],{"type":37,"value":1278},"3",{"type":32,"tag":94,"props":1280,"children":1281},{"style":117},[1282],{"type":37,"value":451},{"type":32,"tag":33,"props":1284,"children":1285},{},[1286],{"type":37,"value":1287},"The first run (full refresh) processes all historical data. Each subsequent day adds only new 1-day events. A single day of 100M events scans 3.2GB (thanks to partitioning + clustering), completes in 4 seconds, costs $0.016. Monthly incremental cost: $0.48 — one-three-hundredth of the naive approach.",{"type":32,"tag":40,"props":1289,"children":1291},{"id":1290},"materialized-views-bigquerys-automatic-caching-layer",[1292],{"type":37,"value":1293},"Materialized Views: BigQuery's Automatic Caching Layer",{"type":32,"tag":33,"props":1295,"children":1296},{},[1297,1299,1304],{"type":37,"value":1298},"The incremental model updates on a batch basis (once daily). If you want to add the last hour's data to a real-time dashboard, BigQuery's ",{"type":32,"tag":458,"props":1300,"children":1301},{},[1302],{"type":37,"value":1303},"materialized view",{"type":37,"value":1305}," feature becomes your tool. A materialized view stores a base query physically and auto-refreshes when the source table changes.",{"type":32,"tag":84,"props":1307,"children":1309},{"className":86,"code":1308,"language":88,"meta":16,"style":16},"CREATE MATERIALIZED VIEW `project.dataset.cohort_retention_mv`\nPARTITION BY cohort_date\nCLUSTER BY day_n, metric_name\nAS\nSELECT\n  DATE_TRUNC(u.created_at, DAY) AS cohort_date,\n  DATE_DIFF(e.event_date, u.created_at, DAY) AS day_n,\n  'active_users' AS metric_name,\n  COUNT(DISTINCT u.user_id) AS metric_value\nFROM `project.dataset.events` e\nJOIN `project.dataset.users` u ON e.user_id = u.user_id\nWHERE e.event_date >= CURRENT_DATE() - 90  -- Only 90-day window\n  AND e.event_name = 'session_start'\nGROUP BY 1, 2, 3;\n",[1310],{"type":32,"tag":52,"props":1311,"children":1312},{"__ignoreMap":16},[1313,1331,1349,1367,1375,1382,1421,1476,1491,1530,1547,1596,1637,1664],{"type":32,"tag":94,"props":1314,"children":1315},{"class":96,"line":97},[1316,1321,1326],{"type":32,"tag":94,"props":1317,"children":1318},{"style":111},[1319],{"type":37,"value":1320},"CREATE",{"type":32,"tag":94,"props":1322,"children":1323},{"style":117},[1324],{"type":37,"value":1325}," MATERIALIZED VIEW ",{"type":32,"tag":94,"props":1327,"children":1328},{"style":367},[1329],{"type":37,"value":1330},"`project.dataset.cohort_retention_mv`\n",{"type":32,"tag":94,"props":1332,"children":1333},{"class":96,"line":107},[1334,1339,1344],{"type":32,"tag":94,"props":1335,"children":1336},{"style":111},[1337],{"type":37,"value":1338},"PARTITION",{"type":32,"tag":94,"props":1340,"children":1341},{"style":111},[1342],{"type":37,"value":1343}," BY",{"type":32,"tag":94,"props":1345,"children":1346},{"style":117},[1347],{"type":37,"value":1348}," cohort_date\n",{"type":32,"tag":94,"props":1350,"children":1351},{"class":96,"line":123},[1352,1357,1362],{"type":32,"tag":94,"props":1353,"children":1354},{"style":117},[1355],{"type":37,"value":1356},"CLUSTER ",{"type":32,"tag":94,"props":1358,"children":1359},{"style":111},[1360],{"type":37,"value":1361},"BY",{"type":32,"tag":94,"props":1363,"children":1364},{"style":117},[1365],{"type":37,"value":1366}," day_n, metric_name\n",{"type":32,"tag":94,"props":1368,"children":1369},{"class":96,"line":172},[1370],{"type":32,"tag":94,"props":1371,"children":1372},{"style":111},[1373],{"type":37,"value":1374},"AS\n",{"type":32,"tag":94,"props":1376,"children":1377},{"class":96,"line":232},[1378],{"type":32,"tag":94,"props":1379,"children":1380},{"style":111},[1381],{"type":37,"value":1019},{"type":32,"tag":94,"props":1383,"children":1384},{"class":96,"line":278},[1385,1389,1393,1397,1401,1405,1409,1413,1417],{"type":32,"tag":94,"props":1386,"children":1387},{"style":117},[1388],{"type":37,"value":129},{"type":32,"tag":94,"props":1390,"children":1391},{"style":132},[1392],{"type":37,"value":135},{"type":32,"tag":94,"props":1394,"children":1395},{"style":117},[1396],{"type":37,"value":140},{"type":32,"tag":94,"props":1398,"children":1399},{"style":132},[1400],{"type":37,"value":145},{"type":32,"tag":94,"props":1402,"children":1403},{"style":117},[1404],{"type":37,"value":59},{"type":32,"tag":94,"props":1406,"children":1407},{"style":111},[1408],{"type":37,"value":154},{"type":32,"tag":94,"props":1410,"children":1411},{"style":117},[1412],{"type":37,"value":159},{"type":32,"tag":94,"props":1414,"children":1415},{"style":111},[1416],{"type":37,"value":164},{"type":32,"tag":94,"props":1418,"children":1419},{"style":117},[1420],{"type":37,"value":169},{"type":32,"tag":94,"props":1422,"children":1423},{"class":96,"line":292},[1424,1428,1432,1436,1440,1444,1448,1452,1456,1460,1464,1468,1472],{"type":32,"tag":94,"props":1425,"children":1426},{"style":117},[1427],{"type":37,"value":178},{"type":32,"tag":94,"props":1429,"children":1430},{"style":132},[1431],{"type":37,"value":183},{"type":32,"tag":94,"props":1433,"children":1434},{"style":117},[1435],{"type":37,"value":140},{"type":32,"tag":94,"props":1437,"children":1438},{"style":132},[1439],{"type":37,"value":192},{"type":32,"tag":94,"props":1441,"children":1442},{"style":117},[1443],{"type":37,"value":59},{"type":32,"tag":94,"props":1445,"children":1446},{"style":132},[1447],{"type":37,"value":135},{"type":32,"tag":94,"props":1449,"children":1450},{"style":117},[1451],{"type":37,"value":140},{"type":32,"tag":94,"props":1453,"children":1454},{"style":132},[1455],{"type":37,"value":145},{"type":32,"tag":94,"props":1457,"children":1458},{"style":117},[1459],{"type":37,"value":59},{"type":32,"tag":94,"props":1461,"children":1462},{"style":111},[1463],{"type":37,"value":154},{"type":32,"tag":94,"props":1465,"children":1466},{"style":117},[1467],{"type":37,"value":159},{"type":32,"tag":94,"props":1469,"children":1470},{"style":111},[1471],{"type":37,"value":164},{"type":32,"tag":94,"props":1473,"children":1474},{"style":117},[1475],{"type":37,"value":229},{"type":32,"tag":94,"props":1477,"children":1478},{"class":96,"line":26},[1479,1483,1487],{"type":32,"tag":94,"props":1480,"children":1481},{"style":367},[1482],{"type":37,"value":1046},{"type":32,"tag":94,"props":1484,"children":1485},{"style":111},[1486],{"type":37,"value":1051},{"type":32,"tag":94,"props":1488,"children":1489},{"style":117},[1490],{"type":37,"value":1056},{"type":32,"tag":94,"props":1492,"children":1493},{"class":96,"line":373},[1494,1498,1502,1506,1510,1514,1518,1522,1526],{"type":32,"tag":94,"props":1495,"children":1496},{"style":132},[1497],{"type":37,"value":238},{"type":32,"tag":94,"props":1499,"children":1500},{"style":117},[1501],{"type":37,"value":243},{"type":32,"tag":94,"props":1503,"children":1504},{"style":111},[1505],{"type":37,"value":248},{"type":32,"tag":94,"props":1507,"children":1508},{"style":132},[1509],{"type":37,"value":253},{"type":32,"tag":94,"props":1511,"children":1512},{"style":117},[1513],{"type":37,"value":140},{"type":32,"tag":94,"props":1515,"children":1516},{"style":132},[1517],{"type":37,"value":262},{"type":32,"tag":94,"props":1519,"children":1520},{"style":117},[1521],{"type":37,"value":159},{"type":32,"tag":94,"props":1523,"children":1524},{"style":111},[1525],{"type":37,"value":164},{"type":32,"tag":94,"props":1527,"children":1528},{"style":117},[1529],{"type":37,"value":1086},{"type":32,"tag":94,"props":1531,"children":1532},{"class":96,"line":404},[1533,1537,1542],{"type":32,"tag":94,"props":1534,"children":1535},{"style":111},[1536],{"type":37,"value":284},{"type":32,"tag":94,"props":1538,"children":1539},{"style":367},[1540],{"type":37,"value":1541}," `project.dataset.events`",{"type":32,"tag":94,"props":1543,"children":1544},{"style":117},[1545],{"type":37,"value":1546}," e\n",{"type":32,"tag":94,"props":1548,"children":1549},{"class":96,"line":427},[1550,1554,1559,1564,1568,1572,1576,1580,1584,1588,1592],{"type":32,"tag":94,"props":1551,"children":1552},{"style":111},[1553],{"type":37,"value":298},{"type":32,"tag":94,"props":1555,"children":1556},{"style":367},[1557],{"type":37,"value":1558}," `project.dataset.users`",{"type":32,"tag":94,"props":1560,"children":1561},{"style":117},[1562],{"type":37,"value":1563}," u ",{"type":32,"tag":94,"props":1565,"children":1566},{"style":111},[1567],{"type":37,"value":308},{"type":32,"tag":94,"props":1569,"children":1570},{"style":132},[1571],{"type":37,"value":330},{"type":32,"tag":94,"props":1573,"children":1574},{"style":117},[1575],{"type":37,"value":140},{"type":32,"tag":94,"props":1577,"children":1578},{"style":132},[1579],{"type":37,"value":262},{"type":32,"tag":94,"props":1581,"children":1582},{"style":111},[1583],{"type":37,"value":325},{"type":32,"tag":94,"props":1585,"children":1586},{"style":132},[1587],{"type":37,"value":253},{"type":32,"tag":94,"props":1589,"children":1590},{"style":117},[1591],{"type":37,"value":140},{"type":32,"tag":94,"props":1593,"children":1594},{"style":132},[1595],{"type":37,"value":339},{"type":32,"tag":94,"props":1597,"children":1598},{"class":96,"line":683},[1599,1603,1607,1611,1615,1619,1623,1627,1632],{"type":32,"tag":94,"props":1600,"children":1601},{"style":111},[1602],{"type":37,"value":347},{"type":32,"tag":94,"props":1604,"children":1605},{"style":132},[1606],{"type":37,"value":330},{"type":32,"tag":94,"props":1608,"children":1609},{"style":117},[1610],{"type":37,"value":140},{"type":32,"tag":94,"props":1612,"children":1613},{"style":132},[1614],{"type":37,"value":192},{"type":32,"tag":94,"props":1616,"children":1617},{"style":111},[1618],{"type":37,"value":364},{"type":32,"tag":94,"props":1620,"children":1621},{"style":117},[1622],{"type":37,"value":978},{"type":32,"tag":94,"props":1624,"children":1625},{"style":111},[1626],{"type":37,"value":983},{"type":32,"tag":94,"props":1628,"children":1629},{"style":132},[1630],{"type":37,"value":1631}," 90",{"type":32,"tag":94,"props":1633,"children":1634},{"style":101},[1635],{"type":37,"value":1636},"  -- Only 90-day window\n",{"type":32,"tag":94,"props":1638,"children":1639},{"class":96,"line":696},[1640,1644,1648,1652,1656,1660],{"type":32,"tag":94,"props":1641,"children":1642},{"style":111},[1643],{"type":37,"value":379},{"type":32,"tag":94,"props":1645,"children":1646},{"style":132},[1647],{"type":37,"value":330},{"type":32,"tag":94,"props":1649,"children":1650},{"style":117},[1651],{"type":37,"value":140},{"type":32,"tag":94,"props":1653,"children":1654},{"style":132},[1655],{"type":37,"value":392},{"type":32,"tag":94,"props":1657,"children":1658},{"style":111},[1659],{"type":37,"value":325},{"type":32,"tag":94,"props":1661,"children":1662},{"style":367},[1663],{"type":37,"value":401},{"type":32,"tag":94,"props":1665,"children":1666},{"class":96,"line":717},[1667,1671,1675,1679,1683,1687,1691],{"type":32,"tag":94,"props":1668,"children":1669},{"style":111},[1670],{"type":37,"value":410},{"type":32,"tag":94,"props":1672,"children":1673},{"style":132},[1674],{"type":37,"value":415},{"type":32,"tag":94,"props":1676,"children":1677},{"style":117},[1678],{"type":37,"value":59},{"type":32,"tag":94,"props":1680,"children":1681},{"style":132},[1682],{"type":37,"value":446},{"type":32,"tag":94,"props":1684,"children":1685},{"style":117},[1686],{"type":37,"value":59},{"type":32,"tag":94,"props":1688,"children":1689},{"style":132},[1690],{"type":37,"value":1278},{"type":32,"tag":94,"props":1692,"children":1693},{"style":117},[1694],{"type":37,"value":451},{"type":32,"tag":33,"props":1696,"children":1697},{},[1698],{"type":37,"value":1699},"When querying the materialized view, BigQuery returns the cached result first. If the base table changes (new events arrive), a delta is calculated in the background. Dashboard query now runs in 0.2 seconds at zero cost (cache hit). Note: the materialized view itself incurs storage costs (BigQuery storage: $0.02\u002FGB\u002Fmonth), so a 90-day cohort table of 12GB costs $0.24 monthly.",{"type":32,"tag":33,"props":1701,"children":1702},{},[1703],{"type":32,"tag":458,"props":1704,"children":1705},{},[1706],{"type":37,"value":1707},"Tradeoff table:",{"type":32,"tag":1709,"props":1710,"children":1711},"table",{},[1712,1746],{"type":32,"tag":1713,"props":1714,"children":1715},"thead",{},[1716],{"type":32,"tag":1717,"props":1718,"children":1719},"tr",{},[1720,1726,1731,1736,1741],{"type":32,"tag":1721,"props":1722,"children":1723},"th",{},[1724],{"type":37,"value":1725},"Method",{"type":32,"tag":1721,"props":1727,"children":1728},{},[1729],{"type":37,"value":1730},"First Query Time",{"type":32,"tag":1721,"props":1732,"children":1733},{},[1734],{"type":37,"value":1735},"Dashboard Query Time",{"type":32,"tag":1721,"props":1737,"children":1738},{},[1739],{"type":37,"value":1740},"Monthly Compute Cost",{"type":32,"tag":1721,"props":1742,"children":1743},{},[1744],{"type":37,"value":1745},"Monthly Storage Cost",{"type":32,"tag":1747,"props":1748,"children":1749},"tbody",{},[1750,1778,1806],{"type":32,"tag":1717,"props":1751,"children":1752},{},[1753,1759,1764,1768,1773],{"type":32,"tag":1754,"props":1755,"children":1756},"td",{},[1757],{"type":37,"value":1758},"Naive JOIN",{"type":32,"tag":1754,"props":1760,"children":1761},{},[1762],{"type":37,"value":1763},"12s",{"type":32,"tag":1754,"props":1765,"children":1766},{},[1767],{"type":37,"value":1763},{"type":32,"tag":1754,"props":1769,"children":1770},{},[1771],{"type":37,"value":1772},"$144,000",{"type":32,"tag":1754,"props":1774,"children":1775},{},[1776],{"type":37,"value":1777},"$0",{"type":32,"tag":1717,"props":1779,"children":1780},{},[1781,1786,1791,1796,1801],{"type":32,"tag":1754,"props":1782,"children":1783},{},[1784],{"type":37,"value":1785},"dbt Incremental",{"type":32,"tag":1754,"props":1787,"children":1788},{},[1789],{"type":37,"value":1790},"4s (first batch)",{"type":32,"tag":1754,"props":1792,"children":1793},{},[1794],{"type":37,"value":1795},"2s (snapshot read)",{"type":32,"tag":1754,"props":1797,"children":1798},{},[1799],{"type":37,"value":1800},"$0.48",{"type":32,"tag":1754,"props":1802,"children":1803},{},[1804],{"type":37,"value":1805},"$0.18 (snapshot table)",{"type":32,"tag":1717,"props":1807,"children":1808},{},[1809,1814,1819,1824,1829],{"type":32,"tag":1754,"props":1810,"children":1811},{},[1812],{"type":37,"value":1813},"Materialized View",{"type":32,"tag":1754,"props":1815,"children":1816},{},[1817],{"type":37,"value":1818},"8s (first build)",{"type":32,"tag":1754,"props":1820,"children":1821},{},[1822],{"type":37,"value":1823},"0.2s (cache hit)",{"type":32,"tag":1754,"props":1825,"children":1826},{},[1827],{"type":37,"value":1828},"$0 (auto-refresh)",{"type":32,"tag":1754,"props":1830,"children":1831},{},[1832],{"type":37,"value":1833},"$0.24",{"type":32,"tag":33,"props":1835,"children":1836},{},[1837,1839,1844,1846,1850],{"type":37,"value":1838},"In production, combining both works best: ",{"type":32,"tag":458,"props":1840,"children":1841},{},[1842],{"type":37,"value":1843},"dbt incremental model",{"type":37,"value":1845}," updates historical cohorts with daily batches, while ",{"type":32,"tag":458,"props":1847,"children":1848},{},[1849],{"type":37,"value":1303},{"type":37,"value":1851}," keeps the last 7 days real-time.",{"type":32,"tag":40,"props":1853,"children":1855},{"id":1854},"partitioning-and-clustering-cutting-query-cost-by-97",[1856],{"type":37,"value":1857},"Partitioning and Clustering: Cutting Query Cost by 97%",{"type":32,"tag":33,"props":1859,"children":1860},{},[1861],{"type":37,"value":1862},"Without partitioning and clustering your cohort tables, BigQuery scans the entire table on every query. On a 1TB cohort table (2 years of data), a single \"show me January 2026 cohort\" query scans 1TB and costs $5. With partitioning + clustering, the same query scans 8GB and costs $0.04.",{"type":32,"tag":33,"props":1864,"children":1865},{},[1866,1871,1873,1879],{"type":32,"tag":458,"props":1867,"children":1868},{},[1869],{"type":37,"value":1870},"Partitioning strategy:",{"type":37,"value":1872}," Daily partition by ",{"type":32,"tag":52,"props":1874,"children":1876},{"className":1875},[],[1877],{"type":37,"value":1878},"cohort_date",{"type":37,"value":1880},". When BigQuery sees a partition filter in the query, it scans only relevant partitions.",{"type":32,"tag":84,"props":1882,"children":1884},{"className":86,"code":1883,"language":88,"meta":16,"style":16},"CREATE OR REPLACE TABLE `project.dataset.cohort_retention`\nPARTITION BY cohort_date\nCLUSTER BY day_n, metric_name\nAS\nSELECT * FROM `project.dataset.cohort_retention_temp`;\n",[1885],{"type":32,"tag":52,"props":1886,"children":1887},{"__ignoreMap":16},[1888,1915,1930,1945,1952],{"type":32,"tag":94,"props":1889,"children":1890},{"class":96,"line":97},[1891,1895,1900,1905,1910],{"type":32,"tag":94,"props":1892,"children":1893},{"style":111},[1894],{"type":37,"value":1320},{"type":32,"tag":94,"props":1896,"children":1897},{"style":111},[1898],{"type":37,"value":1899}," OR",{"type":32,"tag":94,"props":1901,"children":1902},{"style":111},[1903],{"type":37,"value":1904}," REPLACE",{"type":32,"tag":94,"props":1906,"children":1907},{"style":111},[1908],{"type":37,"value":1909}," TABLE",{"type":32,"tag":94,"props":1911,"children":1912},{"style":367},[1913],{"type":37,"value":1914}," `project.dataset.cohort_retention`\n",{"type":32,"tag":94,"props":1916,"children":1917},{"class":96,"line":107},[1918,1922,1926],{"type":32,"tag":94,"props":1919,"children":1920},{"style":111},[1921],{"type":37,"value":1338},{"type":32,"tag":94,"props":1923,"children":1924},{"style":111},[1925],{"type":37,"value":1343},{"type":32,"tag":94,"props":1927,"children":1928},{"style":117},[1929],{"type":37,"value":1348},{"type":32,"tag":94,"props":1931,"children":1932},{"class":96,"line":123},[1933,1937,1941],{"type":32,"tag":94,"props":1934,"children":1935},{"style":117},[1936],{"type":37,"value":1356},{"type":32,"tag":94,"props":1938,"children":1939},{"style":111},[1940],{"type":37,"value":1361},{"type":32,"tag":94,"props":1942,"children":1943},{"style":117},[1944],{"type":37,"value":1366},{"type":32,"tag":94,"props":1946,"children":1947},{"class":96,"line":172},[1948],{"type":32,"tag":94,"props":1949,"children":1950},{"style":111},[1951],{"type":37,"value":1374},{"type":32,"tag":94,"props":1953,"children":1954},{"class":96,"line":232},[1955,1959,1964,1969,1974],{"type":32,"tag":94,"props":1956,"children":1957},{"style":111},[1958],{"type":37,"value":114},{"type":32,"tag":94,"props":1960,"children":1961},{"style":111},[1962],{"type":37,"value":1963}," *",{"type":32,"tag":94,"props":1965,"children":1966},{"style":111},[1967],{"type":37,"value":1968}," FROM",{"type":32,"tag":94,"props":1970,"children":1971},{"style":367},[1972],{"type":37,"value":1973}," `project.dataset.cohort_retention_temp`",{"type":32,"tag":94,"props":1975,"children":1976},{"style":117},[1977],{"type":37,"value":451},{"type":32,"tag":33,"props":1979,"children":1980},{},[1981,1986,1988,1994,1995,2001],{"type":32,"tag":458,"props":1982,"children":1983},{},[1984],{"type":37,"value":1985},"Clustering:",{"type":37,"value":1987}," When you cluster frequently filtered fields (like ",{"type":32,"tag":52,"props":1989,"children":1991},{"className":1990},[],[1992],{"type":37,"value":1993},"day_n",{"type":37,"value":59},{"type":32,"tag":52,"props":1996,"children":1998},{"className":1997},[],[1999],{"type":37,"value":2000},"metric_name",{"type":37,"value":2002},") within partitions, BigQuery performs block-level pruning. A \"show day_7 retention + active_users metric\" query reads only relevant blocks.",{"type":32,"tag":33,"props":2004,"children":2005},{},[2006,2008,2014],{"type":37,"value":2007},"Concrete example: 365 partitions (daily), 3GB each, without clustering a \"day_7\" filter scans 365 partitions × 3GB = 1TB. With clustering, only ",{"type":32,"tag":52,"props":2009,"children":2011},{"className":2010},[],[2012],{"type":37,"value":2013},"day_n=7",{"type":37,"value":2015}," blocks are scanned, totaling 12GB. Cost difference: $5 → $0.06.",{"type":32,"tag":33,"props":2017,"children":2018},{},[2019,2024,2026,2031,2033,2038],{"type":32,"tag":458,"props":2020,"children":2021},{},[2022],{"type":37,"value":2023},"Anti-pattern:",{"type":37,"value":2025}," Don't cluster by ",{"type":32,"tag":52,"props":2027,"children":2029},{"className":2028},[],[2030],{"type":37,"value":262},{"type":37,"value":2032},". Cohort analysis is cohort-level aggregation, not user-level. Clustering by ",{"type":32,"tag":52,"props":2034,"children":2036},{"className":2035},[],[2037],{"type":37,"value":262},{"type":37,"value":2039}," doesn't help the query planner and actually reduces cache efficiency.",{"type":32,"tag":40,"props":2041,"children":2043},{"id":2042},"identity-resolution-for-cohort-accuracy",[2044],{"type":37,"value":2045},"Identity Resolution for Cohort Accuracy",{"type":32,"tag":33,"props":2047,"children":2048},{},[2049,2051,2056,2058,2067,2069,2075,2077,2082],{"type":37,"value":2050},"Cohort analysis accuracy depends on ",{"type":32,"tag":52,"props":2052,"children":2054},{"className":2053},[],[2055],{"type":37,"value":262},{"type":37,"value":2057}," precision. When cookie-based sessions and post-login sessions belong to the same user, a naive JOIN creates two separate cohort records. This is solved with ",{"type":32,"tag":2059,"props":2060,"children":2064},"a",{"href":2061,"rel":2062},"https:\u002F\u002Fwww.roibase.com.tr\u002Fde\u002Ffirstparty",[2063],"nofollow",[2065],{"type":37,"value":2066},"First-Party Data & Measurement Architecture",{"type":37,"value":2068},": an identity graph connects anonymous ",{"type":32,"tag":52,"props":2070,"children":2072},{"className":2071},[],[2073],{"type":37,"value":2074},"client_id",{"type":37,"value":2076}," to authenticated ",{"type":32,"tag":52,"props":2078,"children":2080},{"className":2079},[],[2081],{"type":37,"value":262},{"type":37,"value":140},{"type":32,"tag":84,"props":2084,"children":2086},{"className":86,"code":2085,"language":88,"meta":16,"style":16},"-- Identity resolution table\nCREATE TABLE `project.dataset.identity_graph` (\n  canonical_user_id STRING,\n  client_id STRING,\n  user_id STRING,\n  merged_at TIMESTAMP\n)\nPARTITION BY DATE(merged_at)\nCLUSTER BY canonical_user_id;\n\n-- Join with cohort query\nWITH resolved_users AS (\n  SELECT \n    COALESCE(ig.canonical_user_id, e.user_id) AS user_id,\n    e.event_date,\n    e.event_name\n  FROM events e\n  LEFT JOIN identity_graph ig \n    ON e.client_id = ig.client_id OR e.user_id = ig.user_id\n)\nSELECT \n  DATE_TRUNC(u.created_at, DAY) AS cohort_date,\n  DATE_DIFF(r.event_date, u.created_at, DAY) AS day_n,\n  COUNT(DISTINCT r.user_id) AS retained_users\nFROM resolved_users r\nJOIN users u ON r.user_id = u.user_id\nGROUP BY 1, 2;\n",[2087],{"type":32,"tag":52,"props":2088,"children":2089},{"__ignoreMap":16},[2090,2098,2118,2126,2134,2142,2155,2162,2183,2199,2206,2214,2234,2245,2300,2319,2335,2347,2360,2429,2436,2447,2486,2542,2582,2594,2638],{"type":32,"tag":94,"props":2091,"children":2092},{"class":96,"line":97},[2093],{"type":32,"tag":94,"props":2094,"children":2095},{"style":101},[2096],{"type":37,"value":2097},"-- Identity resolution table\n",{"type":32,"tag":94,"props":2099,"children":2100},{"class":96,"line":107},[2101,2105,2109,2114],{"type":32,"tag":94,"props":2102,"children":2103},{"style":111},[2104],{"type":37,"value":1320},{"type":32,"tag":94,"props":2106,"children":2107},{"style":111},[2108],{"type":37,"value":1909},{"type":32,"tag":94,"props":2110,"children":2111},{"style":367},[2112],{"type":37,"value":2113}," `project.dataset.identity_graph`",{"type":32,"tag":94,"props":2115,"children":2116},{"style":117},[2117],{"type":37,"value":680},{"type":32,"tag":94,"props":2119,"children":2120},{"class":96,"line":123},[2121],{"type":32,"tag":94,"props":2122,"children":2123},{"style":117},[2124],{"type":37,"value":2125},"  canonical_user_id STRING,\n",{"type":32,"tag":94,"props":2127,"children":2128},{"class":96,"line":172},[2129],{"type":32,"tag":94,"props":2130,"children":2131},{"style":117},[2132],{"type":37,"value":2133},"  client_id STRING,\n",{"type":32,"tag":94,"props":2135,"children":2136},{"class":96,"line":232},[2137],{"type":32,"tag":94,"props":2138,"children":2139},{"style":117},[2140],{"type":37,"value":2141},"  user_id STRING,\n",{"type":32,"tag":94,"props":2143,"children":2144},{"class":96,"line":278},[2145,2150],{"type":32,"tag":94,"props":2146,"children":2147},{"style":117},[2148],{"type":37,"value":2149},"  merged_at ",{"type":32,"tag":94,"props":2151,"children":2152},{"style":111},[2153],{"type":37,"value":2154},"TIMESTAMP\n",{"type":32,"tag":94,"props":2156,"children":2157},{"class":96,"line":292},[2158],{"type":32,"tag":94,"props":2159,"children":2160},{"style":117},[2161],{"type":37,"value":1010},{"type":32,"tag":94,"props":2163,"children":2164},{"class":96,"line":26},[2165,2169,2173,2178],{"type":32,"tag":94,"props":2166,"children":2167},{"style":111},[2168],{"type":37,"value":1338},{"type":32,"tag":94,"props":2170,"children":2171},{"style":111},[2172],{"type":37,"value":1343},{"type":32,"tag":94,"props":2174,"children":2175},{"style":111},[2176],{"type":37,"value":2177}," DATE",{"type":32,"tag":94,"props":2179,"children":2180},{"style":117},[2181],{"type":37,"value":2182},"(merged_at)\n",{"type":32,"tag":94,"props":2184,"children":2185},{"class":96,"line":373},[2186,2190,2194],{"type":32,"tag":94,"props":2187,"children":2188},{"style":117},[2189],{"type":37,"value":1356},{"type":32,"tag":94,"props":2191,"children":2192},{"style":111},[2193],{"type":37,"value":1361},{"type":32,"tag":94,"props":2195,"children":2196},{"style":117},[2197],{"type":37,"value":2198}," canonical_user_id;\n",{"type":32,"tag":94,"props":2200,"children":2201},{"class":96,"line":404},[2202],{"type":32,"tag":94,"props":2203,"children":2204},{"emptyLinePlaceholder":655},[2205],{"type":37,"value":658},{"type":32,"tag":94,"props":2207,"children":2208},{"class":96,"line":427},[2209],{"type":32,"tag":94,"props":2210,"children":2211},{"style":101},[2212],{"type":37,"value":2213},"-- Join with cohort query\n",{"type":32,"tag":94,"props":2215,"children":2216},{"class":96,"line":683},[2217,2221,2226,2230],{"type":32,"tag":94,"props":2218,"children":2219},{"style":111},[2220],{"type":37,"value":666},{"type":32,"tag":94,"props":2222,"children":2223},{"style":117},[2224],{"type":37,"value":2225}," resolved_users ",{"type":32,"tag":94,"props":2227,"children":2228},{"style":111},[2229],{"type":37,"value":164},{"type":32,"tag":94,"props":2231,"children":2232},{"style":117},[2233],{"type":37,"value":680},{"type":32,"tag":94,"props":2235,"children":2236},{"class":96,"line":696},[2237,2241],{"type":32,"tag":94,"props":2238,"children":2239},{"style":111},[2240],{"type":37,"value":689},{"type":32,"tag":94,"props":2242,"children":2243},{"style":117},[2244],{"type":37,"value":120},{"type":32,"tag":94,"props":2246,"children":2247},{"class":96,"line":717},[2248,2253,2257,2262,2266,2271,2275,2279,2283,2287,2291,2295],{"type":32,"tag":94,"props":2249,"children":2250},{"style":132},[2251],{"type":37,"value":2252},"    COALESCE",{"type":32,"tag":94,"props":2254,"children":2255},{"style":117},[2256],{"type":37,"value":243},{"type":32,"tag":94,"props":2258,"children":2259},{"style":132},[2260],{"type":37,"value":2261},"ig",{"type":32,"tag":94,"props":2263,"children":2264},{"style":117},[2265],{"type":37,"value":140},{"type":32,"tag":94,"props":2267,"children":2268},{"style":132},[2269],{"type":37,"value":2270},"canonical_user_id",{"type":32,"tag":94,"props":2272,"children":2273},{"style":117},[2274],{"type":37,"value":59},{"type":32,"tag":94,"props":2276,"children":2277},{"style":132},[2278],{"type":37,"value":183},{"type":32,"tag":94,"props":2280,"children":2281},{"style":117},[2282],{"type":37,"value":140},{"type":32,"tag":94,"props":2284,"children":2285},{"style":132},[2286],{"type":37,"value":262},{"type":32,"tag":94,"props":2288,"children":2289},{"style":117},[2290],{"type":37,"value":159},{"type":32,"tag":94,"props":2292,"children":2293},{"style":111},[2294],{"type":37,"value":164},{"type":32,"tag":94,"props":2296,"children":2297},{"style":117},[2298],{"type":37,"value":2299}," user_id,\n",{"type":32,"tag":94,"props":2301,"children":2302},{"class":96,"line":758},[2303,2307,2311,2315],{"type":32,"tag":94,"props":2304,"children":2305},{"style":132},[2306],{"type":37,"value":821},{"type":32,"tag":94,"props":2308,"children":2309},{"style":117},[2310],{"type":37,"value":140},{"type":32,"tag":94,"props":2312,"children":2313},{"style":132},[2314],{"type":37,"value":192},{"type":32,"tag":94,"props":2316,"children":2317},{"style":117},[2318],{"type":37,"value":544},{"type":32,"tag":94,"props":2320,"children":2321},{"class":96,"line":815},[2322,2326,2330],{"type":32,"tag":94,"props":2323,"children":2324},{"style":132},[2325],{"type":37,"value":821},{"type":32,"tag":94,"props":2327,"children":2328},{"style":117},[2329],{"type":37,"value":140},{"type":32,"tag":94,"props":2331,"children":2332},{"style":132},[2333],{"type":37,"value":2334},"event_name\n",{"type":32,"tag":94,"props":2336,"children":2337},{"class":96,"line":836},[2338,2342],{"type":32,"tag":94,"props":2339,"children":2340},{"style":111},[2341],{"type":37,"value":859},{"type":32,"tag":94,"props":2343,"children":2344},{"style":117},[2345],{"type":37,"value":2346}," events e\n",{"type":32,"tag":94,"props":2348,"children":2349},{"class":96,"line":853},[2350,2355],{"type":32,"tag":94,"props":2351,"children":2352},{"style":111},[2353],{"type":37,"value":2354},"  LEFT JOIN",{"type":32,"tag":94,"props":2356,"children":2357},{"style":117},[2358],{"type":37,"value":2359}," identity_graph ig \n",{"type":32,"tag":94,"props":2361,"children":2362},{"class":96,"line":877},[2363,2368,2372,2376,2380,2384,2389,2393,2397,2401,2405,2409,2413,2417,2421,2425],{"type":32,"tag":94,"props":2364,"children":2365},{"style":111},[2366],{"type":37,"value":2367},"    ON",{"type":32,"tag":94,"props":2369,"children":2370},{"style":132},[2371],{"type":37,"value":330},{"type":32,"tag":94,"props":2373,"children":2374},{"style":117},[2375],{"type":37,"value":140},{"type":32,"tag":94,"props":2377,"children":2378},{"style":132},[2379],{"type":37,"value":2074},{"type":32,"tag":94,"props":2381,"children":2382},{"style":111},[2383],{"type":37,"value":325},{"type":32,"tag":94,"props":2385,"children":2386},{"style":132},[2387],{"type":37,"value":2388}," ig",{"type":32,"tag":94,"props":2390,"children":2391},{"style":117},[2392],{"type":37,"value":140},{"type":32,"tag":94,"props":2394,"children":2395},{"style":132},[2396],{"type":37,"value":2074},{"type":32,"tag":94,"props":2398,"children":2399},{"style":111},[2400],{"type":37,"value":1899},{"type":32,"tag":94,"props":2402,"children":2403},{"style":132},[2404],{"type":37,"value":330},{"type":32,"tag":94,"props":2406,"children":2407},{"style":117},[2408],{"type":37,"value":140},{"type":32,"tag":94,"props":2410,"children":2411},{"style":132},[2412],{"type":37,"value":262},{"type":32,"tag":94,"props":2414,"children":2415},{"style":111},[2416],{"type":37,"value":325},{"type":32,"tag":94,"props":2418,"children":2419},{"style":132},[2420],{"type":37,"value":2388},{"type":32,"tag":94,"props":2422,"children":2423},{"style":117},[2424],{"type":37,"value":140},{"type":32,"tag":94,"props":2426,"children":2427},{"style":132},[2428],{"type":37,"value":339},{"type":32,"tag":94,"props":2430,"children":2431},{"class":96,"line":932},[2432],{"type":32,"tag":94,"props":2433,"children":2434},{"style":117},[2435],{"type":37,"value":1010},{"type":32,"tag":94,"props":2437,"children":2438},{"class":96,"line":951},[2439,2443],{"type":32,"tag":94,"props":2440,"children":2441},{"style":111},[2442],{"type":37,"value":114},{"type":32,"tag":94,"props":2444,"children":2445},{"style":117},[2446],{"type":37,"value":120},{"type":32,"tag":94,"props":2448,"children":2449},{"class":96,"line":995},[2450,2454,2458,2462,2466,2470,2474,2478,2482],{"type":32,"tag":94,"props":2451,"children":2452},{"style":117},[2453],{"type":37,"value":129},{"type":32,"tag":94,"props":2455,"children":2456},{"style":132},[2457],{"type":37,"value":135},{"type":32,"tag":94,"props":2459,"children":2460},{"style":117},[2461],{"type":37,"value":140},{"type":32,"tag":94,"props":2463,"children":2464},{"style":132},[2465],{"type":37,"value":145},{"type":32,"tag":94,"props":2467,"children":2468},{"style":117},[2469],{"type":37,"value":59},{"type":32,"tag":94,"props":2471,"children":2472},{"style":111},[2473],{"type":37,"value":154},{"type":32,"tag":94,"props":2475,"children":2476},{"style":117},[2477],{"type":37,"value":159},{"type":32,"tag":94,"props":2479,"children":2480},{"style":111},[2481],{"type":37,"value":164},{"type":32,"tag":94,"props":2483,"children":2484},{"style":117},[2485],{"type":37,"value":169},{"type":32,"tag":94,"props":2487,"children":2488},{"class":96,"line":1004},[2489,2493,2498,2502,2506,2510,2514,2518,2522,2526,2530,2534,2538],{"type":32,"tag":94,"props":2490,"children":2491},{"style":117},[2492],{"type":37,"value":178},{"type":32,"tag":94,"props":2494,"children":2495},{"style":132},[2496],{"type":37,"value":2497},"r",{"type":32,"tag":94,"props":2499,"children":2500},{"style":117},[2501],{"type":37,"value":140},{"type":32,"tag":94,"props":2503,"children":2504},{"style":132},[2505],{"type":37,"value":192},{"type":32,"tag":94,"props":2507,"children":2508},{"style":117},[2509],{"type":37,"value":59},{"type":32,"tag":94,"props":2511,"children":2512},{"style":132},[2513],{"type":37,"value":135},{"type":32,"tag":94,"props":2515,"children":2516},{"style":117},[2517],{"type":37,"value":140},{"type":32,"tag":94,"props":2519,"children":2520},{"style":132},[2521],{"type":37,"value":145},{"type":32,"tag":94,"props":2523,"children":2524},{"style":117},[2525],{"type":37,"value":59},{"type":32,"tag":94,"props":2527,"children":2528},{"style":111},[2529],{"type":37,"value":154},{"type":32,"tag":94,"props":2531,"children":2532},{"style":117},[2533],{"type":37,"value":159},{"type":32,"tag":94,"props":2535,"children":2536},{"style":111},[2537],{"type":37,"value":164},{"type":32,"tag":94,"props":2539,"children":2540},{"style":117},[2541],{"type":37,"value":229},{"type":32,"tag":94,"props":2543,"children":2544},{"class":96,"line":1013},[2545,2549,2553,2557,2562,2566,2570,2574,2578],{"type":32,"tag":94,"props":2546,"children":2547},{"style":132},[2548],{"type":37,"value":238},{"type":32,"tag":94,"props":2550,"children":2551},{"style":117},[2552],{"type":37,"value":243},{"type":32,"tag":94,"props":2554,"children":2555},{"style":111},[2556],{"type":37,"value":248},{"type":32,"tag":94,"props":2558,"children":2559},{"style":132},[2560],{"type":37,"value":2561}," r",{"type":32,"tag":94,"props":2563,"children":2564},{"style":117},[2565],{"type":37,"value":140},{"type":32,"tag":94,"props":2567,"children":2568},{"style":132},[2569],{"type":37,"value":262},{"type":32,"tag":94,"props":2571,"children":2572},{"style":117},[2573],{"type":37,"value":159},{"type":32,"tag":94,"props":2575,"children":2576},{"style":111},[2577],{"type":37,"value":164},{"type":32,"tag":94,"props":2579,"children":2580},{"style":117},[2581],{"type":37,"value":275},{"type":32,"tag":94,"props":2583,"children":2584},{"class":96,"line":1022},[2585,2589],{"type":32,"tag":94,"props":2586,"children":2587},{"style":111},[2588],{"type":37,"value":284},{"type":32,"tag":94,"props":2590,"children":2591},{"style":117},[2592],{"type":37,"value":2593}," resolved_users r\n",{"type":32,"tag":94,"props":2595,"children":2596},{"class":96,"line":1031},[2597,2601,2606,2610,2614,2618,2622,2626,2630,2634],{"type":32,"tag":94,"props":2598,"children":2599},{"style":111},[2600],{"type":37,"value":298},{"type":32,"tag":94,"props":2602,"children":2603},{"style":117},[2604],{"type":37,"value":2605}," users u ",{"type":32,"tag":94,"props":2607,"children":2608},{"style":111},[2609],{"type":37,"value":308},{"type":32,"tag":94,"props":2611,"children":2612},{"style":132},[2613],{"type":37,"value":2561},{"type":32,"tag":94,"props":2615,"children":2616},{"style":117},[2617],{"type":37,"value":140},{"type":32,"tag":94,"props":2619,"children":2620},{"style":132},[2621],{"type":37,"value":262},{"type":32,"tag":94,"props":2623,"children":2624},{"style":111},[2625],{"type":37,"value":325},{"type":32,"tag":94,"props":2627,"children":2628},{"style":132},[2629],{"type":37,"value":253},{"type":32,"tag":94,"props":2631,"children":2632},{"style":117},[2633],{"type":37,"value":140},{"type":32,"tag":94,"props":2635,"children":2636},{"style":132},[2637],{"type":37,"value":339},{"type":32,"tag":94,"props":2639,"children":2640},{"class":96,"line":1040},[2641,2645,2649,2653,2657],{"type":32,"tag":94,"props":2642,"children":2643},{"style":111},[2644],{"type":37,"value":410},{"type":32,"tag":94,"props":2646,"children":2647},{"style":132},[2648],{"type":37,"value":415},{"type":32,"tag":94,"props":2650,"children":2651},{"style":117},[2652],{"type":37,"value":59},{"type":32,"tag":94,"props":2654,"children":2655},{"style":132},[2656],{"type":37,"value":446},{"type":32,"tag":94,"props":2658,"children":2659},{"style":117},[2660],{"type":37,"value":451},{"type":32,"tag":33,"props":2662,"children":2663},{},[2664],{"type":37,"value":2665},"Without identity resolution, cohorts inflate by 12-18% (one user recorded under two IDs). This error makes retention metrics look artificially low because the denominator (cohort size) inflates while numerator (day_n activity) stays the same.",{"type":32,"tag":40,"props":2667,"children":2669},{"id":2668},"query-cost-monitoring-production-monitoring-with-information_schema",[2670],{"type":37,"value":2671},"Query Cost Monitoring: Production Monitoring with INFORMATION_SCHEMA",{"type":32,"tag":33,"props":2673,"children":2674},{},[2675,2677,2683],{"type":37,"value":2676},"Once cohort architecture is in place, continuous query cost optimization is needed. BigQuery's ",{"type":32,"tag":52,"props":2678,"children":2680},{"className":2679},[],[2681],{"type":37,"value":2682},"INFORMATION_SCHEMA.JOBS",{"type":37,"value":2684}," table shows bytes scanned, slot usage, and total cost for every query.",{"type":32,"tag":84,"props":2686,"children":2688},{"className":86,"code":2687,"language":88,"meta":16,"style":16},"SELECT\n  user_email,\n  query,\n  total_bytes_processed \u002F POW(10, 12) AS tb_processed,\n  (total_bytes_processed \u002F POW(10, 12)) * 5 AS cost_usd,\n  total_slot_ms \u002F 1000 \u002F 60 AS slot_minutes\nFROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_PROJECT\nWHERE creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)\n  AND statement_type = 'SELECT'\n  AND query LIKE '%cohort_retention%'\nORDER BY total_bytes_processed DESC\nLIMIT 20;\n",[2689],{"type":32,"tag":52,"props":2690,"children":2691},{"__ignoreMap":16},[2692,2699,2707,2715,2760,2812,2848,2878,2924,2945,2967,2984],{"type":32,"tag":94,"props":2693,"children":2694},{"class":96,"line":97},[2695],{"type":32,"tag":94,"props":2696,"children":2697},{"style":111},[2698],{"type":37,"value":1019},{"type":32,"tag":94,"props":2700,"children":2701},{"class":96,"line":107},[2702],{"type":32,"tag":94,"props":2703,"children":2704},{"style":117},[2705],{"type":37,"value":2706},"  user_email,\n",{"type":32,"tag":94,"props":2708,"children":2709},{"class":96,"line":123},[2710],{"type":32,"tag":94,"props":2711,"children":2712},{"style":117},[2713],{"type":37,"value":2714},"  query,\n",{"type":32,"tag":94,"props":2716,"children":2717},{"class":96,"line":172},[2718,2723,2728,2733,2738,2742,2747,2751,2755],{"type":32,"tag":94,"props":2719,"children":2720},{"style":117},[2721],{"type":37,"value":2722},"  total_bytes_processed ",{"type":32,"tag":94,"props":2724,"children":2725},{"style":111},[2726],{"type":37,"value":2727},"\u002F",{"type":32,"tag":94,"props":2729,"children":2730},{"style":117},[2731],{"type":37,"value":2732}," POW(",{"type":32,"tag":94,"props":2734,"children":2735},{"style":132},[2736],{"type":37,"value":2737},"10",{"type":32,"tag":94,"props":2739,"children":2740},{"style":117},[2741],{"type":37,"value":59},{"type":32,"tag":94,"props":2743,"children":2744},{"style":132},[2745],{"type":37,"value":2746},"12",{"type":32,"tag":94,"props":2748,"children":2749},{"style":117},[2750],{"type":37,"value":159},{"type":32,"tag":94,"props":2752,"children":2753},{"style":111},[2754],{"type":37,"value":164},{"type":32,"tag":94,"props":2756,"children":2757},{"style":117},[2758],{"type":37,"value":2759}," tb_processed,\n",{"type":32,"tag":94,"props":2761,"children":2762},{"class":96,"line":232},[2763,2768,2772,2776,2780,2784,2788,2793,2798,2803,2807],{"type":32,"tag":94,"props":2764,"children":2765},{"style":117},[2766],{"type":37,"value":2767},"  (total_bytes_processed ",{"type":32,"tag":94,"props":2769,"children":2770},{"style":111},[2771],{"type":37,"value":2727},{"type":32,"tag":94,"props":2773,"children":2774},{"style":117},[2775],{"type":37,"value":2732},{"type":32,"tag":94,"props":2777,"children":2778},{"style":132},[2779],{"type":37,"value":2737},{"type":32,"tag":94,"props":2781,"children":2782},{"style":117},[2783],{"type":37,"value":59},{"type":32,"tag":94,"props":2785,"children":2786},{"style":132},[2787],{"type":37,"value":2746},{"type":32,"tag":94,"props":2789,"children":2790},{"style":117},[2791],{"type":37,"value":2792},")) ",{"type":32,"tag":94,"props":2794,"children":2795},{"style":111},[2796],{"type":37,"value":2797},"*",{"type":32,"tag":94,"props":2799,"children":2800},{"style":132},[2801],{"type":37,"value":2802}," 5",{"type":32,"tag":94,"props":2804,"children":2805},{"style":111},[2806],{"type":37,"value":1051},{"type":32,"tag":94,"props":2808,"children":2809},{"style":117},[2810],{"type":37,"value":2811}," cost_usd,\n",{"type":32,"tag":94,"props":2813,"children":2814},{"class":96,"line":278},[2815,2820,2824,2829,2834,2839,2843],{"type":32,"tag":94,"props":2816,"children":2817},{"style":117},[2818],{"type":37,"value":2819},"  total_slot_ms ",{"type":32,"tag":94,"props":2821,"children":2822},{"style":111},[2823],{"type":37,"value":2727},{"type":32,"tag":94,"props":2825,"children":2826},{"style":132},[2827],{"type":37,"value":2828}," 1000",{"type":32,"tag":94,"props":2830,"children":2831},{"style":111},[2832],{"type":37,"value":2833}," \u002F",{"type":32,"tag":94,"props":2835,"children":2836},{"style":132},[2837],{"type":37,"value":2838}," 60",{"type":32,"tag":94,"props":2840,"children":2841},{"style":111},[2842],{"type":37,"value":1051},{"type":32,"tag":94,"props":2844,"children":2845},{"style":117},[2846],{"type":37,"value":2847}," slot_minutes\n",{"type":32,"tag":94,"props":2849,"children":2850},{"class":96,"line":292},[2851,2855,2860,2864,2869,2873],{"type":32,"tag":94,"props":2852,"children":2853},{"style":111},[2854],{"type":37,"value":284},{"type":32,"tag":94,"props":2856,"children":2857},{"style":367},[2858],{"type":37,"value":2859}," `region-us`",{"type":32,"tag":94,"props":2861,"children":2862},{"style":117},[2863],{"type":37,"value":140},{"type":32,"tag":94,"props":2865,"children":2866},{"style":132},[2867],{"type":37,"value":2868},"INFORMATION_SCHEMA",{"type":32,"tag":94,"props":2870,"children":2871},{"style":117},[2872],{"type":37,"value":140},{"type":32,"tag":94,"props":2874,"children":2875},{"style":132},[2876],{"type":37,"value":2877},"JOBS_BY_PROJECT\n",{"type":32,"tag":94,"props":2879,"children":2880},{"class":96,"line":26},[2881,2885,2890,2895,2900,2905,2910,2915,2920],{"type":32,"tag":94,"props":2882,"children":2883},{"style":111},[2884],{"type":37,"value":347},{"type":32,"tag":94,"props":2886,"children":2887},{"style":117},[2888],{"type":37,"value":2889}," creation_time ",{"type":32,"tag":94,"props":2891,"children":2892},{"style":111},[2893],{"type":37,"value":2894},">=",{"type":32,"tag":94,"props":2896,"children":2897},{"style":117},[2898],{"type":37,"value":2899}," TIMESTAMP_SUB(",{"type":32,"tag":94,"props":2901,"children":2902},{"style":132},[2903],{"type":37,"value":2904},"CURRENT_TIMESTAMP",{"type":32,"tag":94,"props":2906,"children":2907},{"style":117},[2908],{"type":37,"value":2909},"(), INTERVAL ",{"type":32,"tag":94,"props":2911,"children":2912},{"style":132},[2913],{"type":37,"value":2914},"7",{"type":32,"tag":94,"props":2916,"children":2917},{"style":111},[2918],{"type":37,"value":2919}," DAY",{"type":32,"tag":94,"props":2921,"children":2922},{"style":117},[2923],{"type":37,"value":1010},{"type":32,"tag":94,"props":2925,"children":2926},{"class":96,"line":373},[2927,2931,2936,2940],{"type":32,"tag":94,"props":2928,"children":2929},{"style":111},[2930],{"type":37,"value":379},{"type":32,"tag":94,"props":2932,"children":2933},{"style":117},[2934],{"type":37,"value":2935}," statement_type ",{"type":32,"tag":94,"props":2937,"children":2938},{"style":111},[2939],{"type":37,"value":534},{"type":32,"tag":94,"props":2941,"children":2942},{"style":367},[2943],{"type":37,"value":2944}," 'SELECT'\n",{"type":32,"tag":94,"props":2946,"children":2947},{"class":96,"line":404},[2948,2952,2957,2962],{"type":32,"tag":94,"props":2949,"children":2950},{"style":111},[2951],{"type":37,"value":379},{"type":32,"tag":94,"props":2953,"children":2954},{"style":117},[2955],{"type":37,"value":2956}," query ",{"type":32,"tag":94,"props":2958,"children":2959},{"style":111},[2960],{"type":37,"value":2961},"LIKE",{"type":32,"tag":94,"props":2963,"children":2964},{"style":367},[2965],{"type":37,"value":2966}," '%cohort_retention%'\n",{"type":32,"tag":94,"props":2968,"children":2969},{"class":96,"line":427},[2970,2974,2979],{"type":32,"tag":94,"props":2971,"children":2972},{"style":111},[2973],{"type":37,"value":433},{"type":32,"tag":94,"props":2975,"children":2976},{"style":117},[2977],{"type":37,"value":2978}," total_bytes_processed ",{"type":32,"tag":94,"props":2980,"children":2981},{"style":111},[2982],{"type":37,"value":2983},"DESC\n",{"type":32,"tag":94,"props":2985,"children":2986},{"class":96,"line":683},[2987,2992,2997],{"type":32,"tag":94,"props":2988,"children":2989},{"style":111},[2990],{"type":37,"value":2991},"LIMIT",{"type":32,"tag":94,"props":2993,"children":2994},{"style":132},[2995],{"type":37,"value":2996}," 20",{"type":32,"tag":94,"props":2998,"children":2999},{"style":117},[3000],{"type":37,"value":451},{"type":32,"tag":33,"props":3002,"children":3003},{},[3004,3006,3012],{"type":37,"value":3005},"This query lists cohort table queries from the past 7 days ranked by cost. If a dashboard panel triggers 500 times daily and scans 80GB each time (missing partition filter), it generates 500 × 80GB × $5\u002FTB = $200 daily cost. Adding ",{"type":32,"tag":52,"props":3007,"children":3009},{"className":3008},[],[3010],{"type":37,"value":3011},"WHERE cohort_date >= CURRENT_DATE() - 30",{"type":37,"value":3013}," to the panel query drops cost to $6.",{"type":32,"tag":33,"props":3015,"children":3016},{},[3017],{"type":32,"tag":458,"props":3018,"children":3019},{},[3020],{"type":37,"value":3021},"Production checklist:",{"type":32,"tag":3023,"props":3024,"children":3027},"ul",{"className":3025},[3026],"contains-task-list",[3028,3048,3070,3079,3088,3105],{"type":32,"tag":3029,"props":3030,"children":3033},"li",{"className":3031},[3032],"task-list-item",[3034,3039,3041,3046],{"type":32,"tag":3035,"props":3036,"children":3038},"input",{"disabled":655,"type":3037},"checkbox",[],{"type":37,"value":3040}," All cohort tables partitioned by ",{"type":32,"tag":52,"props":3042,"children":3044},{"className":3043},[],[3045],{"type":37,"value":1878},{"type":37,"value":3047},"?",{"type":32,"tag":3029,"props":3049,"children":3051},{"className":3050},[3032],[3052,3055,3057,3062,3063,3068],{"type":32,"tag":3035,"props":3053,"children":3054},{"disabled":655,"type":3037},[],{"type":37,"value":3056}," ",{"type":32,"tag":52,"props":3058,"children":3060},{"className":3059},[],[3061],{"type":37,"value":1993},{"type":37,"value":464},{"type":32,"tag":52,"props":3064,"children":3066},{"className":3065},[],[3067],{"type":37,"value":2000},{"type":37,"value":3069}," clustered?",{"type":32,"tag":3029,"props":3071,"children":3073},{"className":3072},[3032],[3074,3077],{"type":32,"tag":3035,"props":3075,"children":3076},{"disabled":655,"type":3037},[],{"type":37,"value":3078}," dbt incremental job running daily?",{"type":32,"tag":3029,"props":3080,"children":3082},{"className":3081},[3032],[3083,3086],{"type":32,"tag":3035,"props":3084,"children":3085},{"disabled":655,"type":3037},[],{"type":37,"value":3087}," Materialized view constrained to 90-day window?",{"type":32,"tag":3029,"props":3089,"children":3091},{"className":3090},[3032],[3092,3095,3097,3103],{"type":32,"tag":3035,"props":3093,"children":3094},{"disabled":655,"type":3037},[],{"type":37,"value":3096}," Dashboard queries include ",{"type":32,"tag":52,"props":3098,"children":3100},{"className":3099},[],[3101],{"type":37,"value":3102},"WHERE cohort_date >= ...",{"type":37,"value":3104}," filter?",{"type":32,"tag":3029,"props":3106,"children":3108},{"className":3107},[3032],[3109,3112,3114,3119],{"type":32,"tag":3035,"props":3110,"children":3111},{"disabled":655,"type":3037},[],{"type":37,"value":3113}," Weekly cost report pulled from ",{"type":32,"tag":52,"props":3115,"children":3117},{"className":3116},[],[3118],{"type":37,"value":2868},{"type":37,"value":3047},{"type":32,"tag":33,"props":3121,"children":3122},{},[3123],{"type":37,"value":3124},"When cohort architecture is built correctly, retention analysis reaches production readiness: 100M daily events, 5-second query time, $10 monthly compute cost. But this architecture requires first-party identity resolution, event schema standardization, and dbt pipeline discipline — which is why retention engineering is platform work, not one-off SQL.",{"type":32,"tag":3126,"props":3127,"children":3128},"style",{},[3129],{"type":37,"value":3130},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":16,"searchDepth":123,"depth":123,"links":3132},[3133,3136,3137,3138,3139],{"id":42,"depth":107,"text":45,"children":3134},[3135],{"id":474,"depth":123,"text":477},{"id":1290,"depth":107,"text":1293},{"id":1854,"depth":107,"text":1857},{"id":2042,"depth":107,"text":2045},{"id":2668,"depth":107,"text":2671},"markdown","content:de:data:cohort-table-architecture-production-scaling.md","content","de\u002Fdata\u002Fcohort-table-architecture-production-scaling.md","de\u002Fdata\u002Fcohort-table-architecture-production-scaling","md",1782079489422]