FORTILABS TECH LAB
Real-Time Analytics at Scale: ClickHouse vs Embedded DuckDB for SaaS Telemetry
When PostgreSQL or MySQL struggles with hundreds of millions of telemetry events, the next step is not necessarily a bigger transactional database. Compare ClickHouse, DuckDB, and MotherDuck across ingestion, distinct counts, compression, concurrency, and infrastructure cost.
The short answer
ClickHouse is usually the stronger starting point for a shared, continuously updated analytics backend. Its columnar storage, parallel query execution, ingestion integrations, and distributed architecture are designed for large analytical datasets and concurrent workloads.
DuckDB is an excellent choice when analytics should execute close to the application or data pipeline. It is embedded, vectorized, and efficient for local analytical processing, data transformations, batch reporting, and workloads where one process controls database access.
MotherDuck is worth evaluating when a team wants DuckDB’s SQL experience with a managed collaborative cloud service. It changes the deployment and concurrency model, but it is not simply an embedded DuckDB database running on a bigger machine.
For a SaaS product serving many customers and dashboard requests over continuously arriving telemetry, ClickHouse is generally the more natural analytical serving layer. DuckDB or MotherDuck can be a better fit for embedded analytics, data preparation, customer-specific analysis, and smaller or less concurrent workloads.
Why PostgreSQL and MySQL struggle with large-scale SaaS telemetry
A transactional database is often the right place to store customers, subscriptions, invoices, authentication records, and application state. Problems appear when the same database also becomes the analytical engine for every product dashboard, usage report, and event-level investigation.
Imagine a SaaS application recording:
- Page views, API requests, and feature usage.
- Login events, sessions, and authentication activity.
- Customer actions, workflow executions, and application errors.
- Usage-based billing events and quota consumption.
- Geographic, device, browser, and plan-level telemetry.
At hundreds of millions of records, analytical queries can become expensive even when the transactional workload is relatively small. A dashboard that calculates unique users by tenant, groups events by hour, and filters by multiple dimensions may scan and aggregate a large portion of the event history.
Why COUNT(DISTINCT) becomes expensive
A query such as COUNT(DISTINCT user_id) must identify unique values within the selected data. Depending on the database and query plan, this can require substantial memory, sorting, hashing, or intermediate aggregation state.
The problem becomes more difficult when the query includes several dimensions:
- Unique active users per customer and day.
- Distinct API keys per endpoint and billing period.
- Unique sessions by country, device, and subscription tier.
- Daily and monthly rollups over hundreds of millions of events.
Running these queries against the same database that handles application transactions can create contention for CPU, memory, disk I/O, and connection capacity. Indexes can improve selective lookups, but they do not turn a row-oriented transactional schema into a dedicated analytical engine.
ClickHouse vs DuckDB vs MotherDuck: three different architectures
ClickHouse: distributed columnar analytics
ClickHouse is a column-oriented analytical database built to process large volumes of structured data. Instead of reading complete rows when a query needs only a few fields, it can read the relevant columns and execute filtering, aggregation, and other operations in parallel.
Its MergeTree family of table engines provides sorted, immutable data parts, sparse primary indexes, background merges, and configurable partitioning and ordering. Sharding and replication allow deployments to scale across multiple servers, while ClickHouse Cloud separates compute and storage through its managed architecture.
This makes ClickHouse a natural fit for telemetry platforms that continuously ingest events and serve analytical queries from many users or application services.
DuckDB: an embedded analytical engine
DuckDB is designed to run inside the process that uses it. An application, Python service, notebook, command-line tool, or data pipeline can open a database and execute analytical SQL without operating a separate database server.
Its vectorized execution engine processes data in batches rather than evaluating every row as an isolated operation. It also supports parallel execution and can spill certain larger-than-memory operations to disk.
This model is particularly effective when the application controls the workload and can execute analytics close to the data. It is not automatically a shared database service for hundreds of independent application workers.
MotherDuck: DuckDB extended into the cloud
MotherDuck combines DuckDB with a managed cloud service. Its hybrid query processing model can execute work across local DuckDB and cloud resources, enabling users to work with shared cloud data while retaining the familiar DuckDB SQL experience.
This is an important distinction: comparing embedded DuckDB directly with ClickHouse Cloud ignores the additional infrastructure and service capabilities MotherDuck provides. For customer-facing analytics, evaluate MotherDuck as a cloud database service, not merely as an embedded library.
| Dimension | ClickHouse | DuckDB | MotherDuck |
|---|---|---|---|
| Deployment | Standalone server, cluster, or managed cloud | Embedded in an application or process | Managed cloud service with DuckDB integration |
| Primary workload | Shared analytical serving at scale | In-process analytics and data processing | Collaborative cloud analytics and shared datasets |
| Execution | Parallelized columnar execution | Vectorized in-process execution | DuckDB execution with local/cloud hybrid processing |
| Horizontal scaling | Distributed sharding and replication | Not a distributed server cluster by itself | Managed cloud scaling features and read-scaling options |
| Concurrent users | Designed for concurrent server-side queries | Concurrency within a process; important multi-process write limitations | Managed multi-user cloud access, subject to plan and compute limits |
| Operations | Self-managed or managed service | Library and application lifecycle management | Managed service operations and usage billing |
COUNT(DISTINCT), rollups, and analytical query performance
Distinct counting is one of the most important workloads to evaluate when a SaaS team moves beyond transactional reporting. It is also an area where benchmark claims need careful interpretation.
Exact distinct counts versus approximate cardinality
Exact distinct counting must identify every unique value in the selected data. Approximate algorithms estimate cardinality using compact statistical structures, reducing memory and computation at the cost of a small error.
ClickHouse provides both approaches:
uniqExact(user_id)calculates an exact distinct count, with state size that grows with the number of unique values.uniq(user_id)uses an approximate adaptive algorithm with a compact aggregation state.
These are not interchangeable results. A billing system that must calculate an exact billable quantity may require exact semantics. A product dashboard showing estimated daily active users may be able to use an approximation.
DuckDB also supports exact COUNT(DISTINCT ...) and approximate aggregate functions such as approx_count_distinct. Its performance depends on data volume, cardinality, available memory, thread count, and the rest of the query plan.
Why ClickHouse suits repeated telemetry aggregations
ClickHouse can distribute scans and partial aggregation across CPU cores and, in distributed deployments, across multiple servers. This is particularly useful when queries repeatedly group large event datasets by time, tenant, region, endpoint, or other dimensions.
Materialized views and aggregate-state functions can also move work away from dashboard request time. For example, a pipeline can maintain daily or hourly aggregate states as new events arrive, then merge those states when a dashboard requests a larger time range.
However, pre-aggregation must match the reporting semantics. A daily count of unique users cannot simply be summed to obtain a monthly unique-user count because the same user may appear on multiple days. Use mergeable aggregate states or recompute the distinct set at the required scope.
Why DuckDB can still be extremely competitive
DuckDB can perform very well on analytical queries when the data is local, the workload is controlled, and there is enough CPU and memory available. For a developer running a report over Parquet files, or a background job computing a customer’s usage summary, avoiding a network hop to a separate database server can be valuable.
It is not correct to conclude that ClickHouse always wins every aggregation. DuckDB may be faster for an individual query on a particular dataset and hardware configuration. The more important question for a SaaS backend is whether that performance remains predictable when many independent users submit expensive queries simultaneously.
Real-time ingestion: Kafka, HTTP, and application pipelines
An analytical database must keep up with the event stream without allowing ingestion to overwhelm query performance. The right ingestion architecture depends on event volume, batching, delivery guarantees, schema evolution, and the amount of transformation required before data becomes queryable.
ClickHouse: Kafka ingestion and direct HTTP inserts
ClickHouse supports multiple ingestion paths. Applications can send batches through the HTTP interface, while streaming pipelines can integrate Kafka through the Kafka table engine, materialized views, or Kafka Connect integrations.
A common architecture is to expose a Kafka-backed source table and use a materialized view to transform incoming messages into a MergeTree destination table. This separates the event transport layer from the analytical storage layer and gives teams control over schema mapping and transformations.
Direct HTTP ingestion is also useful for application services and batch loaders. For production workloads, batch inserts rather than sending one insert per event. ClickHouse recommends substantial batches for synchronous inserts; asynchronous inserts can help when many clients generate smaller batches.
With asynchronous inserts, wait_for_async_insert=1 is the safer production setting when the client needs confirmation that the buffered data was flushed successfully. Setting it to zero acknowledges after buffering and can expose data to loss if the server fails before the flush completes.
DuckDB: ingest through the application or data pipeline
DuckDB can read and transform data from supported files, object storage, and data formats such as Parquet. An application can also insert records through its client libraries and use SQL to process batches.
For a Kafka-based production event stream, however, teams should plan an ingestion component that consumes Kafka and delivers batches into DuckDB or writes files that DuckDB can query. DuckDB is not a direct replacement for a distributed message broker and does not provide ClickHouse’s equivalent built-in server-side Kafka ingestion architecture.
This approach works well for controlled pipelines, scheduled transformations, and local analytical jobs. It requires more architectural care when the application has many independently deployed processes attempting to write to the same database file.
MotherDuck: cloud analytics ingestion
MotherDuck can serve as the cloud destination for DuckDB-based data workflows. Teams can use DuckDB’s integration ecosystem and external pipeline tools to prepare and load data, then query shared cloud datasets.
Do not assume that a DuckDB-compatible workflow automatically provides the same ingestion behavior as ClickHouse’s Kafka engine. Evaluate connector support, batch sizing, delivery guarantees, data freshness, and the operational cost of the pipeline separately.
| Ingestion requirement | ClickHouse | DuckDB | MotherDuck |
|---|---|---|---|
| Kafka pipeline | Kafka engine, materialized views, and Kafka Connect options | External consumer or pipeline required | External pipeline or supported integration required |
| Direct HTTP writes | Native HTTP interface | Client libraries and application-level integration | Cloud connectivity through supported clients and workflows |
| Small frequent batches | Use batching or asynchronous inserts carefully | Prefer controlled batched operations | Evaluate service and query metering for write patterns |
| Continuous high-volume ingestion | Designed for continuously ingested analytical data | Typically needs an external ingestion and scheduling layer | Depends on pipeline design, service capacity, and pricing |
| Data freshness | Depends on insert batching, flush, and materialized-view processing | Depends on the application’s ingest and commit cycle | Depends on pipeline delivery and cloud write visibility |
Columnar compression and storage efficiency
Telemetry datasets often contain repeated timestamps, status codes, tenant identifiers, event types, numeric measurements, and other values with predictable distributions. These patterns make columnar storage particularly effective.
Why ClickHouse compresses analytical data efficiently
ClickHouse stores data in columns and can apply type-aware encodings and compression codecs. A timestamp column can benefit from delta or double-delta encoding; repeated categorical values can benefit from dictionary-style representations; numeric metrics can use codecs suited to their value patterns.
The table’s sort key also matters. When data is ordered by columns frequently used in filters, related values can become easier to compress and queries can skip irrelevant ranges more effectively.
ClickHouse supports codecs such as LZ4 and ZSTD, along with specialized encodings. LZ4 is often useful when fast decompression is important, while ZSTD can reduce storage further at a higher CPU cost. The right choice depends on whether the workload is more sensitive to CPU, disk, network, or storage expense.
DuckDB and Parquet compression
DuckDB can store data in its native columnar database format and query external Parquet datasets. Parquet provides columnar storage and compression options that work well for analytical data lakes and file-based pipelines.
This makes DuckDB especially useful when analytics can operate directly over partitioned Parquet files without loading everything into a traditional database server. It also allows data engineers to reuse datasets across multiple tools.
Compression ratios are workload-specific
A claim such as “10× compression” should never be treated as a guaranteed result. The actual ratio depends on event schema, cardinality, sort order, data types, null patterns, payload fields, and codec settings.
A dataset containing repeated event names and low-cardinality status fields may compress extremely well. Arbitrary JSON strings, unique identifiers, encrypted payloads, and high-entropy text may compress much less.
| Dimension | ClickHouse | DuckDB |
|---|---|---|
| Storage format | Columnar MergeTree parts | Native columnar database format and external analytical files |
| Compression | Column codecs and type-aware encodings | Native storage compression and supported external file codecs |
| Parquet workflow | Can query and integrate with Parquet-based data architectures | First-class analytical workflow for Parquet files |
| Optimization lever | ORDER BY, partitioning, data types, codecs, and granularity | Data types, row groups, file partitioning, and compression settings |
| Best measurement | Compressed bytes per row and per column | Native database and Parquet bytes for the same logical dataset |
Memory consumption and concurrent analytical requests
This is often the deciding factor for customer-facing SaaS analytics. A database that performs an individual query quickly may behave very differently when 50, 100, or 500 customers refresh dashboards at the same time.
ClickHouse: server-side query controls and workload isolation
ClickHouse executes analytical work across CPU threads and uses memory for aggregation states, sorting, joins, caches, and intermediate results. Exact distinct counting can be particularly memory-intensive because the engine must maintain the unique values or their aggregation state.
ClickHouse provides controls such as query memory limits, maximum concurrent queries, user profiles, workload settings, and resource isolation mechanisms. These help prevent a single expensive tenant query from consuming all resources available to the service.
For SaaS analytics, teams should implement per-user or per-tenant limits, sensible time-range constraints, query timeouts, and workload separation where necessary. ClickHouse Cloud can also separate compute workloads through its service architecture and available scaling features.
DuckDB: parallel execution inside a process
DuckDB supports multi-threaded execution and can process larger-than-memory workloads by spilling supported operations to disk. Its memory requirements depend on the query plan, data volume, join cardinality, aggregation state, and configured thread count.
DuckDB’s documented concurrency model is important: within a process, it supports concurrent work using its transaction and concurrency mechanisms. For multiple processes, read-only access is supported, but multiple independent processes writing to the same native database file are not the standard supported model.
This is a significant consideration for a horizontally scaled web application. If every application worker opens its own DuckDB file and attempts to write telemetry, the deployment can become difficult to coordinate. A single controlled writer process or a different storage and ingestion architecture may be necessary.
MotherDuck: managed multi-user cloud access
MotherDuck changes the deployment model by providing shared cloud databases and managed compute. Its plan and service features include user access controls, service accounts, compute instances, and read-scaling options, subject to the selected plan.
This makes it more suitable than a single embedded DuckDB file when several users or services need shared access. However, teams still need to evaluate compute capacity, query concurrency, service limits, data transfer, and the cost of repeated dashboard queries.
| Workload concern | ClickHouse | DuckDB | MotherDuck |
|---|---|---|---|
| Many independent dashboard users | Natural server-side use case | Requires application-level process and resource management | Managed shared-cloud use case, subject to plan capacity |
| Memory-heavy exact distinct | Aggregation state can be large; apply query limits and choose exact or approximate semantics | Memory use depends on cardinality, execution plan, and thread count | Depends on selected compute resources and query execution |
| Parallel query execution | Multi-threaded and distributed execution | Multi-threaded in-process execution | Managed cloud compute with supported scaling features |
| Multi-process writes | Server coordinates concurrent clients | Single read-write process for native database files | Shared cloud service handles client access |
| Resource protection | Query limits, users, profiles, and workload controls | Application-managed connections, threads, and memory limits | Service plans, compute selection, and managed controls |
Managed cloud vs self-hosted: the real operational cost
Database cost should be measured as total cost of ownership, not just the monthly compute invoice. A self-hosted system may have lower direct infrastructure costs but require engineers to manage upgrades, backups, monitoring, replication, scaling, and incident response.
Self-hosted ClickHouse
Self-hosting can be attractive when the team has infrastructure expertise, predictable workloads, and the ability to operate Linux servers and distributed databases. The organization controls hardware, storage, network topology, and deployment schedules.
The cost model should include:
- Compute nodes and memory capacity.
- Fast local storage or block storage.
- Replica and backup storage.
- Cross-zone network transfer.
- Monitoring, alerting, and log retention.
- Engineering time for upgrades, capacity planning, and recovery.
ClickHouse Cloud
ClickHouse Cloud reduces the operational burden by managing the database service and providing cloud-oriented compute and storage capabilities. The service can scale resources without requiring the team to build and maintain every component of a cluster.
Managed service pricing should be modeled using the actual region, compute configuration, active runtime, storage, backups, data transfer, and workload separation requirements. A low-cost development service is not a reliable proxy for a production deployment serving hundreds of customer dashboards.
Self-hosted DuckDB
DuckDB itself is an embedded engine, so there is no separate database server cluster to operate. It can be inexpensive for a local analytics job, a data transformation process, or a small application with controlled access.
The cost shifts into the application runtime and its operational design. If every web worker needs its own memory allocation, database copy, or synchronization process, the apparent simplicity can become more expensive than expected.
MotherDuck
MotherDuck replaces much of the infrastructure management with a managed cloud service and usage-based compute. Its pricing structure includes organization plans, storage, and compute usage, with features varying by plan.
The published pricing page lists a Business plan starting at $250 per organization per month plus usage, and storage and compute are metered separately. Treat this as a current published starting point rather than a complete production estimate; the final bill depends on workload, selected compute, active users, and service requirements.
Illustrative cost model
Consider a SaaS platform retaining 10 TB of compressed telemetry and serving 100,000 analytical queries per day. This is an example workload for structuring a cost comparison, not a vendor quote or a benchmark result.
| Cost category | Self-hosted ClickHouse | ClickHouse Cloud | DuckDB / MotherDuck |
|---|---|---|---|
| Compute | Broker/server instances and capacity headroom | Service compute and runtime usage | Application CPU or managed query compute |
| Storage | Persistent volumes, replicas, and backups | Managed storage and backup-related charges | Local or object storage, plus managed cloud storage where applicable |
| Networking | Replication, client traffic, and backup transfer | Service and cloud data transfer charges | Data movement, cloud access, and application transfer |
| Operations | Highest direct operational responsibility | Lower database infrastructure burden | Low for embedded use; managed service operations for MotherDuck |
| Scaling | Engineering-led capacity planning | Managed scaling options | Application scaling or managed compute scaling |
| Best economic fit | Stable, substantial workloads with capable operators | Teams valuing managed operations and elastic capacity | Embedded processing or collaborative analytics with measured query demand |
Calculate cost per million events and per query
A useful comparison uses normalized unit economics:
- Cost per million ingested events = total ingestion-related monthly cost ÷ monthly events × 1,000,000.
- Cost per million analytical queries = total query-serving monthly cost ÷ completed monthly queries × 1,000,000.
- Cost per retained TB-month = storage, replication, and backup costs ÷ retained TB.
- Operational cost = engineering hours × fully loaded hourly cost.
For example, if a system costs $4,000 per month to operate and serves 3 billion analytical queries in that month, the normalized cost is approximately $1.33 per million queries. If another service costs $2,500 but serves only 1 billion queries, its normalized cost is $2.50 per million.
This comparison is only meaningful when both systems serve the same query mix, freshness target, concurrency, and availability requirements. It is not enough to compare monthly invoices.
Recommended SaaS analytics architectures
Pattern 1: PostgreSQL plus ClickHouse for customer-facing analytics
This is a strong default architecture when the product has continuous telemetry ingestion and many customers need shared dashboards.
- PostgreSQL or MySQL remains the system of record for transactional data.
- Application events are published to Kafka or another durable event transport.
- ClickHouse consumes events through a Kafka integration or a controlled ingestion service.
- Materialized views maintain selected aggregates and reporting states.
- The SaaS API queries ClickHouse for dashboards, usage analytics, and event exploration.
This architecture decouples transactional traffic from analytical scans and allows the event pipeline to absorb bursts independently of dashboard traffic.
Pattern 2: DuckDB for embedded and background analytics
DuckDB is a good fit when analytics are local to a service or pipeline rather than exposed as a high-concurrency shared database.
- Export or stream batches of events into a controlled processing service.
- Use DuckDB to transform, join, filter, and aggregate local datasets.
- Write the output to Parquet, object storage, or a reporting destination.
- Use scheduled jobs to refresh customer-specific summaries or internal reports.
This approach is particularly useful for data preparation, offline analysis, internal tools, and workloads where the application controls the number of concurrent database writers.
Pattern 3: MotherDuck for shared cloud analytics
MotherDuck is worth considering when a team prefers DuckDB’s workflow but needs shared cloud data, collaborative access, and managed compute.
- Use supported ingestion tools to move event data into cloud datasets.
- Run analytical SQL using DuckDB-compatible workflows.
- Use service accounts and access controls for application and team access.
- Measure compute usage, read scaling, data freshness, and query concurrency.
Before using it as a customer-facing analytics backend, test the actual dashboard traffic pattern. A service that works well for a small data team may require different compute and pricing assumptions when every SaaS customer can trigger expensive queries.
Multi-tenant design: never trust a tenant filter alone
Whichever engine you select, multi-tenant analytics requires deliberate isolation. Include a tenant identifier in the data model, enforce tenant scoping in the API and database access layer, and apply resource limits to prevent one customer from exhausting shared compute.
In ClickHouse, query users, row policies, resource controls, and carefully designed table keys can help enforce isolation. In DuckDB-based systems, the application must ensure that the correct dataset and tenant context are used for every query. Cloud services add their own access-control mechanisms, but application authorization still matters.
How to benchmark ClickHouse and DuckDB fairly
A single query against a warm local dataset does not represent a production SaaS analytics workload. Build a test that reflects ingestion, query concurrency, tenant isolation, data retention, and the exact aggregation semantics required by the product.
1. Use representative event data
- Hundreds of millions of records, not only a small synthetic sample.
- Realistic tenant distribution and event cardinality.
- Real timestamps, repeated dimensions, and high-cardinality identifiers.
- Representative JSON or text fields, not only compressible numeric columns.
2. Test the actual query mix
- Exact and approximate distinct users per tenant.
- Hourly, daily, and monthly rollups.
- Filtering by time range, event type, region, and subscription plan.
- Top-N endpoints, error rates, and usage breakdowns.
- Joins between event data and customer or subscription dimensions.
3. Test concurrent users
Run the same query mix with 1, 10, 25, 50, and 100 concurrent requests. Measure p50, p95, and p99 query latency, throughput, errors, CPU, peak memory, and queueing. Do not run a single query at a time and infer that the same engine will behave well with many SaaS tenants.
4. Measure ingestion while queries are running
Continuously ingest data while dashboards execute. Measure insert latency, event visibility delay, backlog growth, merge activity, and the effect of ingestion on analytical query latency.
5. Compare the total cost
Include compute, storage, network transfer, backups, managed-service usage, and engineering operations. Measure cost per million events, per million queries, and per retained TB-month.
| Metric | What to measure | Why it matters |
|---|---|---|
| Ingestion throughput | Events/sec and MiB/sec | Confirms the system keeps up with telemetry volume |
| Data freshness | Event arrival to query visibility | Measures actual real-time usefulness |
| Distinct aggregation | Exact and approximate results, latency, and memory | Tests the workload most likely to strain the old OLTP database |
| Concurrency | p95/p99 latency at increasing simultaneous requests | Predicts customer-facing dashboard behavior |
| Memory | Peak resident memory and per-query memory | Reveals scaling and resource contention |
| Compression | Compressed bytes per row and per column | Determines retention and storage economics |
| Cost | Monthly TCO and normalized unit costs | Connects performance to business economics |
Which database should your SaaS team choose?
Choose ClickHouse for shared analytics at scale
Choose ClickHouse when the product continuously ingests large event volumes and serves analytical queries to many customers. It is especially attractive for dashboards, usage analytics, observability, event exploration, and large-scale aggregations where concurrent query performance matters.
It is also a strong candidate when PostgreSQL or MySQL has become overloaded by analytical reads and the team wants a dedicated serving layer rather than further complicating the transactional database.
Choose DuckDB for embedded analytical processing
Choose DuckDB when queries run inside a controlled application or pipeline, data can be processed locally or from analytical files, and the workload does not require a shared distributed database service. It is particularly effective for transformations, local exploration, batch analytics, and developer tooling.
Choose MotherDuck for managed cloud DuckDB workflows
Choose MotherDuck when the team values DuckDB’s SQL and ecosystem but needs shared cloud datasets and managed compute. It can reduce infrastructure work for collaborative analytics, but customer-facing concurrency and query costs should be validated before it becomes the primary analytics backend.
| Requirement | Platform to evaluate first | Reason |
|---|---|---|
| Hundreds of millions of SaaS events | ClickHouse | Columnar storage and analytical serving architecture |
| Many concurrent customer dashboards | ClickHouse | Server-side concurrency and distributed execution |
| Embedded analytics inside one service | DuckDB | In-process execution without a separate database server |
| Local Parquet analytics and transformations | DuckDB | Efficient file-based analytical workflows |
| Managed collaborative DuckDB environment | MotherDuck | Shared cloud data and managed compute |
| Strict exact billing calculations | Benchmark both | Exactness, reproducibility, and resource consumption matter more than approximate speed claims |
| High-volume real-time event ingestion | ClickHouse | Native server-side ingestion patterns and analytical storage |
For most SaaS products outgrowing PostgreSQL or MySQL analytics, the strongest starting architecture is not a complete database replacement. Keep the transactional database for application state, introduce a dedicated event pipeline, and evaluate ClickHouse as the analytical serving layer. Use DuckDB where its embedded execution model provides a simpler and more efficient way to process local or batch data.
Frequently asked questions
Is ClickHouse faster than DuckDB for real-time analytics?
ClickHouse is generally better suited to shared, concurrent analytics over continuously ingested large datasets. DuckDB can be extremely fast for individual in-process analytical queries. The result depends on data size, query plan, hardware, concurrency, and ingestion requirements.
Can DuckDB handle hundreds of millions of rows?
Yes. DuckDB can process datasets containing hundreds of millions of rows and supports larger-than-memory analytical operations by spilling supported workloads to disk. Dataset size alone does not determine whether it is a good fit; concurrent users, memory requirements, and deployment architecture matter as well.
Can DuckDB replace PostgreSQL for a multi-user SaaS backend?
DuckDB is not designed as a conventional multi-process transactional application database. Its native file concurrency model supports a single read-write process and multiple read-only processes. It is better suited to embedded analytics and controlled data-processing workloads than as a direct general-purpose replacement for PostgreSQL.
Does ClickHouse support Kafka ingestion?
Yes. ClickHouse supports Kafka ingestion through its Kafka table engine, materialized views, and Kafka Connect integrations. Teams should configure batching, delivery behavior, schema handling, and insert settings carefully for production.
Is ClickHouse suitable for exact COUNT(DISTINCT) queries?
Yes. ClickHouse supports exact distinct counting through functions such as uniqExact. It also provides approximate functions such as uniq. Exact counting can require substantially more aggregation memory as cardinality increases, so select the function based on the correctness requirement.
Does DuckDB support concurrent queries?
DuckDB supports multi-threaded execution and concurrency within a process. Multiple processes can read a native database in read-only mode, but multiple independent writer processes are not the normal supported model for a native DuckDB database file.
Is MotherDuck the same as embedded DuckDB?
No. MotherDuck is a managed cloud service that integrates with DuckDB and supports hybrid local and cloud query processing. It provides shared cloud capabilities and service features that are not part of a standalone embedded DuckDB database.
How much better does ClickHouse compress telemetry data?
There is no universal compression ratio. ClickHouse can compress analytical data efficiently through columnar storage, type-aware encodings, sort order, and codecs. The result depends on the event schema, cardinality, data distribution, and codec settings. Benchmark representative production data.
Should a SaaS company migrate all PostgreSQL data into ClickHouse?
Usually not. Keep transactional records in PostgreSQL or MySQL and replicate the event data or required dimensions into ClickHouse. This separates transactional and analytical workloads while avoiding an unnecessary migration of application state.