MotherDuck Documentation
website·Indexed 37 days ago
https://motherduck.com/docsA serverless cloud data warehouse built on DuckDB. Documentation covers data warehousing, customer-facing analytics, and architectural concepts including hypertenancy, storage lifecycle management, and workload scaling patterns.
What's inside MotherDuck
- MotherDuck is a serverless cloud data warehouse built on DuckDB. It uses a hypertenancy model where every user or agent is provided a dedicated compute instance, eliminating the need to manage clusters or warehouses. The architecture consists of a cloud service for managed storage and SQL execution, a DuckDB SDK for local integration, and a web UI for analysis and administration.
Overview of MotherDuck as a Cloud Data Warehouse
MotherDuck is a serverless cloud data warehouse built on DuckDB. It uses a hypertenancy architecture where every user, service account, or agent is provided a dedicated compute instance (Duckling) that starts in under a second and bills per second. It integrates with standard data engineering tools for ingestion (dltHub, Estuary, Fivetran, Airbyte), transformation (dbt, dbt Cloud), visualization (Tableau, Power BI, Looker), and orchestration (Airflow, Dagster).Overview of MotherDuck capabilities
MotherDuck is a serverless cloud data warehouse built on DuckDB that provides cloud scalability and collaboration. Key capabilities include:
- Serverless DuckDB: Cloud queries with ~100ms cold starts.
- Hybrid Execution: Ability to query data locally and in the cloud within a single session.
- Cloud Storage Integration: Direct querying of S3, GCS, and Azure Blob Storage.
- AI Integration: Built-in LLM functions for embeddings, text analysis, and SQL generation.
- Connectivity: Supports Python, Node.js, Go, Java, JDBC, ODBC, and a web UI.
Overview of Customer-Facing Analytics (CFA) with MotherDuck
Customer-Facing Analytics (CFA), also known as embedded analytics, involves integrating analytical capabilities directly into a product for external users (customers, partners). Unlike traditional BI, CFA requires sub-second response times, per-customer isolation, and the ability to scale to thousands or millions of concurrent users. MotherDuck enables this using a serverless cloud data warehouse built on DuckDB, focusing on two primary architectural capabilities: Hypertenancy for isolation and Dual Execution for low-latency exploration.Compare MotherDuck CFA implementation patterns
Choose an architecture based on your requirements for latency, data volume, and development effort:
Factor Embedded Dives 3-Tier 1.5-Tier (DuckDB-Wasm) Frontend Effort None (iframe) Custom UI Custom UI Query Latency Sub-second (cloud) ~50-100ms ~5-20ms Server Cost Low (session minting) Medium (per request) Low (data transfer) Data per User Any size Any size <1GB optimal Offline Support No No Yes Server Logic Limited Full Limited Plan Business Plan All Plans All Plans Best For Fast shipping Complex logic/auth Read-heavy dashboards Understand MotherDuck Hypertenancy
MotherDuck uses a tenancy model called hypertenancy, where every user, service account, or agent is assigned a dedicated DuckDB compute instance known as a Duckling. Unlike traditional shared-compute warehouses, this provides full compute isolation at the individual level, eliminating 'noisy neighbor' effects, resource contention, and unpredictable query times. Ducklings feature fast cold starts (under ~100ms) and include dedicated CPU, memory, and SSD spill space.Understand the MotherDuck storage lifecycle stages
MotherDuck uses a multi-stage storage system to manage data safety and billing. Data flows in one direction through these five stages:
- Active bytes: Data currently referenced and accessible via direct queries.
- Historical bytes: Non-active bytes referenced by historical snapshots or shares; used for time travel and self-service restore.
- Retained for clone bytes: (Native storage only) Bytes referenced by zero-copy cloned databases that are no longer active or historical in the source database.
- Failsafe bytes: Bytes no longer referenced by any database or share. These are retained as a last-resort recovery option (requires contacting support, not guaranteed). Standard databases have a 7-day retention; transient databases have a 1-day retention.
- Deleted: Bytes are fully removed and inaccessible.
Understand MotherDuck's Serverless Execution and Parallelization
MotherDuck is aggressively serverless and leverages DuckDB's ability to automatically parallelize workloads across all available resources. Because of this automatic parallelization, scheduling multiple queries simultaneously does not significantly increase throughput.Manage multi-tenant data isolation with Hypertenancy
MotherDuck implements multi-tenant analytics through a concept called 'Hypertenancy'. Unlike shared platforms that may suffer from 'noisy-neighbor' performance issues, Hypertenancy provides every tenant with a dedicated DuckDB instance (referred to as a 'Duckling'). This ensures predictable performance and strict data isolation between customers.Perform Dual Execution between local DuckDB and MotherDuck
Every MotherDuck client functions as a DuckDB engine. This allows users to query local data and perform operations like JOIN or UNION with data stored in the MotherDuck cloud data warehouse. The query planner automatically determines the optimal execution location for each part of the query.Implement Customer-Facing Analytics using a 3-tier architecture
The 3-tier architecture is best for applications requiring server-side authorization, complex business logic, or deployment to stateful platforms (e.g., Kubernetes, ECS). The frontend communicates with an application server (e.g., Express, FastAPI), which maintains a persistent connection to MotherDuck.
Performance Optimizations:
- Connection Pooling: Use persistent connections to save ~200ms per request.
- Query Efficiency: Use a single well-structured SQL statement with multiple aggregates,
CASE/FILTER, orUNION ALLinstead of multiple calls. - Atomicity: Wrap multi-step workflows in
BEGIN ... COMMITtransactions. - Bulk Operations: Use
COPYorINSERT ... SELECTfor data movement rather than row-by-row calls. - Pre-aggregation: Create intermediate tables on MotherDuck to speed up common queries.
- Caching: Cache rarely-changing data on the application server.
Implement Customer-Facing Analytics using a 1.5-tier architecture (DuckDB-Wasm)
The 1.5-tier architecture leverages DuckDB-Wasm to execute queries directly in the user's browser. This is ideal for read-heavy dashboards with less than 1GB of data per user, providing sub-10ms query latency and offline support.
Key Benefits:
- Zero-Latency Exploration: Data processing is offloaded to the client's machine.
- Cost Efficiency: Server costs are limited to data transfer.
- Scalability: Compute scales linearly with the number of users.
Performance Optimizations:
- Initial Load: Use Parquet compression and limit initial data loads to <50MB.
- Persistence: Use IndexedDB to ensure data survives page reloads.
- Syncing: Implement incremental sync to fetch only new data since the last update.