Building Real-time Analytics Apps with ClickHouse and Hex

Dale McDiarmid
18 min readintermediate
--
View Original

Overview

This article discusses the integration of ClickHouse, a high-performance analytical database, with Hex, a modern data workspace, to build real-time analytics applications. It details the process of collecting GitHub repository data and creating a proof-of-concept application called ClickHub, showcasing how users can gain insights into repository activities.

What You'll Learn

1

How to collect and analyze GitHub repository data using ClickHouse

2

Why using KeeperMap table engine enhances job scheduling in ClickHouse

3

How to build interactive data applications with Hex and ClickHouse

Prerequisites & Requirements

  • Understanding of SQL and data analytics concepts
  • Familiarity with ClickHouse and Hex(optional)

Key Questions Answered

How can ClickHouse be utilized for real-time analytics applications?
ClickHouse can be used for real-time analytics applications by leveraging its fast data processing capabilities to analyze large datasets, such as GitHub repository histories. The integration with Hex allows users to create interactive applications that visualize and query this data efficiently.
What is the purpose of the KeeperMap table engine in ClickHouse?
The KeeperMap table engine in ClickHouse is used to create a job queue that ensures each repository is processed by only one worker at a time, preventing duplicate jobs and allowing for prioritized processing. This is crucial for managing large-scale data collection tasks efficiently.
What datasets were collected for the ClickHub application?
The ClickHub application collected the full commit history for 50k GitHub repositories, totaling around 10TB of data, and also included GitHub Events data, which contains approximately 5.8 billion records of various activities on GitHub.

Key Statistics & Figures

Total repositories processed
50035
This number represents the unique repositories for which commit history was collected and analyzed.
Compressed size of ClickHouse data
890.80 GiB
This size indicates the efficiency of data storage in ClickHouse after compression, highlighting its capability to handle large datasets.
Number of rows in line_changes table
44.69 billion
This statistic reflects the extensive detail captured in the commit history, allowing for in-depth analysis of code changes.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Database
Clickhouse
Used for storing and analyzing large datasets, particularly GitHub repository commit histories.
Data Workspace
Hex
Facilitates the creation of interactive data applications and collaborative analysis through SQL and Python notebooks.

Key Actionable Insights

1
Utilize ClickHouse's git-import tool to extract detailed commit history from GitHub repositories for analytics.
This tool allows users to generate TSV files containing commit data, which can then be loaded into ClickHouse for analysis, making it easier to derive insights from repository activities.
2
Leverage Hex's notebook capabilities for ad-hoc analysis of large datasets.
By using Hex, users can quickly analyze terabytes of data through SQL queries and visualizations without extensive coding, streamlining the data exploration process.
3
Implement a queue-worker model to efficiently manage data collection from multiple repositories.
This model allows for scalable data processing by distributing tasks among workers, ensuring that repositories are updated without unnecessary duplication of effort.

Common Pitfalls

1
Failing to manage worker processes effectively can lead to duplicate job processing.
Without a proper queue management system, multiple workers might attempt to process the same repository, causing data inconsistencies and errors.

Related Concepts

Real-time Analytics
Data Visualization
Github API Integration
Data Engineering Best Practices