Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 20 min read How-to mediumAdept

Building single page applications with ClickHouse

ClickHouse can serve as a direct browser-queried backend for single page applications, removing the API server layer for demos, prototypes and analytics UIs. Doing this safely depends on HTTPS-only access, CORS configuration, parameterized queries to prevent SQL injection, read-only users with role-based access control, query complexity limits and quotas to stop rogue clients from overwhelming the database. Practical guidance covers choosing JSON output formats (streamable EachRow variants for large results, Arrow for high-volume rendering), reading progress and summary headers, the `wait_end_of_query` tradeoff, handling mid-stream errors returned with HTTP 200, and preferring the official @clickhouse/client-web library. ClickHouse Cloud Query Endpoints are suggested for teams wanting an API layer instead.

Assumes: SQL basicsJavaScript fetch APIHTTP and CORS

Related posts

  • Announcing the new ClickHouse SQL Playground

    ClickHouse mediumAdept

    sql.clickhouse.com is a new public SQL playground offering over 35 datasets (60 TB) and 220 example queries, with syntax highlighting, autocomplete, query parameters, basic charting via Apache ECharts and shareable links. It is a NextJS/React single-page app talking directly to ClickHouse's HTTP interface. Read-only credentials are exposed safely by combining RBAC, query complexity limits (10 billion rows read, 1000 rows returned) and per-IP quotas of 60 queries per hour. The service runs on a fixed 3-node, 30-vCPU ClickHouse Cloud cluster backed by object storage. Live query progress polls system.processes every 100ms by query ID under a separate monitor user, avoiding HTTP progress headers that the browser fetch API can't read.

  • ClickHouse as a streaming HTTP API

    ClickHouse mediumAdept

    ClickHouse 26.8 can serve a parameterized HTTP API directly, removing the thin API layer often placed in front of it. The walkthrough uses the UK property prices dataset to build endpoints with `CREATE HANDLER`. Handlers support typed query-string parameters and regex-captured path parameters, and a restricted API user supplies a JSONEachRow default format and a per-user row `limit`. Handler queries are checked only for syntax at creation, so missing tables or columns surface at call time. An application layer is still needed for business logic, orchestration or custom validation.

  • ClickHouse Plugin for Grafana - 2.0 Release

    ClickHouse mediumAdept

    Version 2.0 of the ClickHouse Grafana plugin drops its client-side SQL AST parser and implements ad-hoc filters with ClickHouse's new `additional_table_filters` setting (22.7+), so the server injects each filter into the correct clauses, including subqueries. The release also adds HTTP transport via clickhouse-go's native-format-over-HTTP support, which lets traffic go through load balancers and proxies such as ch-proxy, and splits the connection and query timeouts. It adds JSON Object type support, with leaf nodes usable as columns and logs shown in the Explore view and Logs Panel. Breaking changes: the old automatic 'All' variable optimization is replaced by a manual `$__conditionalAll` macro, ad-hoc filters require ClickHouse 22.7+, and read-only users need readonly=2.

  • Adding Analytics to an Application in under 10 minutes with ClickHouse Cloud Query Endpoints

    ClickHouse mediumAdept

    ClickHouse Cloud's beta API endpoints turn a saved parameterized SQL query into a secure HTTP POST endpoint, moving SQL out of application code so queries can change without redeploying. The walkthrough adds GitHub stars, issues, forks and PR counts to the ClickPy PyPI dashboard. A query resolves each package's GitHub repo ID from PyPI metadata and aggregates the GitHub events table with uniqExactIf. The endpoint is bound to a read-only role with IP-keyed quotas and optional CORS, then called from a Next.js/React component via a generic fetch helper, returning any of ClickHouse's output formats such as JSONEachRow.

  • Adding Real Time Analytics to a Supabase Application With ClickHouse

    ClickHouse mediumAdept

    HouseClick, a demo estate-agency app, keeps ~1000 current listings in Supabase Postgres and serves analytics over the ~30M-row UK house price dataset from ClickHouse Cloud. The app first queried ClickHouse directly via its JS client, then switched to Supabase's ClickHouse Foreign Data Wrapper so Postgres pushes queries down to ClickHouse and returns only aggregated results. That gives developers a single SQL interface and lets them join transactional and analytical data without ETL. The post also contrasts OLTP and OLAP workloads and walks through FDW setup, best practices, and options for syncing transactional data into ClickHouse.

The quest for software engineering knowledge.

Look:
Layout: