iQIYI

How iQIYI Runs Ad Analytics and Ad-hoc Lakehouse Queries on StarRocks

iQIYI moved its advertising analytics off Apache Impala and Apache Kudu and about two-thirds of its migrated Spark SQL ad-hoc queries to StarRocks. Ad analytics got 400% faster overall, and the ad-hoc queries that moved run 33x faster at P50.

400%

better ad analytics performance

Overall performance of the advertising platform after StarRocks replaced Apache Impala + Apache Kudu; P90 query latency is 4.6x faster

33x

faster P50 ad-hoc query latency

For Magic Mirror ad-hoc queries moved from Spark SQL to StarRocks (about two-thirds of migrated queries); P90 improved 15x

4.6

person-days freed per day

Analyst time no longer spent waiting on ad-hoc queries, about the capacity of one full-time employee

CompanyiQIYI
Use caseReal-time ad analytics and ad-hoc lakehouse queries
Previous solutionApache Impala + Apache Kudu (ads); Spark SQL (ad-hoc queries)
CloudOn-premises
Employees3,000+
ReplacedApache Impala + Apache Kudu; Spark SQL for about two-thirds of migrated ad-hoc queries

Originally published at: StarRocks Engineering on Medium

About iQIYI

iQIYI is one of the largest online video platforms, serving a pan-Asian entertainment audience that is mostly young and on mobile. Viewers spend about 6 billion hours a month on the service, and it has more than 500 million monthly active users.

Each workload had brought its own OLAP engine, and running all of them had become an operational burden. StarRocks covered both the real-time warehouse path and the lakehouse query path, which gave iQIYI a way to consolidate.

Key takeaway · One engine for warehouse and lake

The original post was written by Hao Lin, Head of Big Data OLAP Services at iQIYI.

iQIYI uses data in two directions. Looking back, it drives reports, series popularity and membership operations. Looking forward, it feeds data products such as search, recommendations and ads, and predictions of user growth and revenue.

The challenge

An engine for every workload

iQIYI's OLAP stack sits on three storage tiers: Apache Hive for offline data, Apache Kafka for real-time data and Apache Iceberg for recent, near-real-time data. Over the years the team added query engines on top as new needs came up. An Intelligent SQL Gateway built in-house (Pilot in the diagrams) keeps that engine mix hidden from the applications above it.

Layered iQIYI OLAP architecture: applications on top, data warehouse layers on Iceberg, StarRocks and Kafka, the Pilot Intelligent SQL Gateway, eight query engines (Hive, Spark, Kylin, Impala/Kudu, Druid, Trino, ClickHouse, StarRocks) and storage on Hive, Iceberg and Kafka
iQIYI's OLAP architecture

Keeping so many engines running took a lot of operations work, so the team decided to cut the number down. On the warehouse side, it had moved from MySQL and Elasticsearch (MySQL did not scale and Elasticsearch was slow) to Apache Impala with Apache Kudu on Hadoop, which performed better but was hard to scale. Apache Druid came next for large time-series data, though it could not serve detail-level queries or joins, and ClickHouse was added for speed. On the lake side, Hive gave way to Apache Spark and Trino for ad-hoc analysis and troubleshooting, where cost mattered most.

StarRocks fit both paths. For the warehouse, it matched ClickHouse on real-time performance and also handled the detailed analytics Druid could not. For the lake, it ran faster than Spark and Trino.

Evolution of iQIYI's query engines: MySQL and Elasticsearch led to Druid; Impala, Kudu, Druid and ClickHouse on one path and Hive, Spark and Trino on the other both converge on StarRocks as a unified data warehouse and lakehouse query engine
How the engine mix converged on StarRocks

Advertising needs consistent data under load

The advertising platform has to answer many concurrent queries with low latency and keep its numbers consistent. It follows a Lambda design: data streams in from Kafka in real time, and offline jobs from Iceberg later overwrite it, for example after anti-fraud corrections. Kudu held the real-time data, HDFS the offline data, and Impala queried both. As data and query volume grew, this setup hit its limits.

Ads data flow: Kafka for real-time ingestion and Iceberg for offline overwrites feed the OLAP engines (Kudu, HDFS, Impala marked slow, ClickHouse marked inconsistent data, StarRocks), which serve high-frequency queries from Ads
OLAP engines evaluated for ads

Why the team ruled out ClickHouse

ClickHouse was evaluated as the replacement. Consistency was the main reason it lost, and two other points added to it:

  • Consistency. ClickHouse's official Flink connector only guarantees at-least-once delivery, so a restarted Apache Flink job can write duplicates. The StarRocks Flink connector supports exactly-once. ClickHouse distributed tables also cannot replace data atomically, so overwrites run one node at a time, and an empty temporary table can wipe the target. StarRocks replaces data atomically per partition.
  • Lake access. ClickHouse reads the lake through external tables, with no unified catalog, and its Iceberg support was weaker when iQIYI evaluated it. For disaster recovery, ClickHouse needs a standby cluster kept in sync, which costs money and maintenance. With StarRocks, the team can start an elastic cluster and query the Hive tables directly as external tables. In iQIYI's tests, those queries performed about as well as queries on internal tables.
  • Operations. iQIYI compares ClickHouse to a manual transmission. Historical data does not rebalance when nodes are added, node failures need manual work to avoid data loss or missing replicas, and shrinking a cluster is close to impossible. StarRocks rebalances on its own and keeps replicas in sync automatically.
Disaster recovery comparison: with ClickHouse, Hive syncs to both the ClickHouse cluster and a ClickHouse DR cluster, and queries are routed to the DR cluster on failure; with StarRocks, Hive syncs only to the StarRocks cluster, and on failure queries are routed to a StarRocks elastic cluster that reads Hive directly
Disaster recovery: ClickHouse vs. StarRocks

The solution

Ads platform on StarRocks

For ads, iQIYI runs two kinds of StarRocks cluster: a shared-nothing cluster with storage and compute on the same physical machines, and an elastic compute cluster. An Alluxio-based cache speeds up the elastic side. The team may later test StarRocks' built-in cache against Alluxio.

The SQL gateway sits on top. It hides engine details such as user credentials, provides high availability and routes each query according to cluster health and performance. Because every SQL statement goes through it, the gateway also records the data the team needs for later tuning and materialized view analysis.

iQIYI's architecture after StarRocks: business scenarios (Ads, Membership, BI Reports, Magic Mirror) over the Pilot SQL Intelligent Gateway with router, HA, query load and monitoring; a storage-unified physical machine cluster and a storage-separate cluster with Alluxio cache; Kafka and Hive/Iceberg below; and a platform station for metadata, aggregation, lifecycle, security and operation
Architecture after StarRocks

Ad-hoc queries in Magic Mirror

Magic Mirror is iQIYI's internal ad-hoc query platform, with more than 500 users and over 1,400 queries a day, all on Spark SQL. Spark was too slow for interactive analysis. Added up, the time analysts spent waiting came to about 12.5 person-days every day.

The team looked at Trino first. However, Trino's SQL differs a lot from Spark SQL, which would have made the move hard. In iQIYI's benchmarks, StarRocks ran 2 to 3 times faster than Trino and accepted Spark SQL syntax well, so the team chose StarRocks.

StarRocksApache KafkaApache IcebergApache HiveHDFSApache FlinkAlluxioIntelligent SQL Gateway (in-house)

The results

Advertising

With StarRocks in place of Impala and Kudu, the ad platform's overall performance improved by 400%, and P90 query latency is 4.6 times faster.

Ad-hoc queries

StarRocks took over from Spark for about two-thirds (67%) of the queries the team tried to migrate. That is a bit lower than the dual-engine tests had suggested. For the queries that did move, P50 latency improved 33x and P90 latency 15x.

Bar chart titled "The Query Speed Improved by 10x After Switching to StarRocks": P50 latency 97.6 on Spark vs. 2.9 on StarRocks, P90 latency 525 on Spark vs. 34 on StarRocks
Ad-hoc query latency, Spark vs. StarRocks

Analysts now wait much less. The change freed 4.6 person-days of analyst time, about what one full-time employee contributes.

Stacked weekly bars of analysts' wait time in milliseconds, split into Spark and StarRocks, falling from 1,918,267,974 in the week of 2024-08-25 to 1,083,720,501 in the week of 2024-09-15
Weekly analyst wait time

What's next

  • Shared-nothing: upgrade to StarRocks 3.3, confirm the benefit of materialized views, look at tiered storage that moves historical data to HDFS, and retire ClickHouse and Druid within the next year.
  • Shared-data: move more query types, fix UDF compatibility to raise the two-thirds migration rate, use materialized views to speed up external-table queries without changing them, and replace Trino.