Real-Time Game Analytics with Streaming SQL: Monetization, Retention, Segmentation, and A/B Tests

Real-Time Game Analytics with Streaming SQL: Monetization, Retention, Segmentation, and A/B Tests

·

Updated

·

18 min read

Real-time game analytics with streaming SQL means DAU, ARPU and ARPPU, onboarding funnels, battle pass progression, economy health, player segments, churn risk, user acquisition return on ad spend, cross-platform behavior, and A/B test results all update within seconds of each install, session, purchase, and XP event. This guide builds the full live-ops analytics layer on RisingWave, a PostgreSQL-compatible streaming database, so product, monetization, growth, and liveops teams act on what players are doing now rather than on yesterday's report.

Why Game Analytics Cannot Wait for the Nightly Batch

Mobile and live-service games run on compressed feedback loops. A player's interest peaks in the first three sessions after install; a broken onboarding flow found in tomorrow's report has already lost thousands of players. A battle pass XP curve that is too steep stalls players at tier 40 of 100 and costs next season's renewals, and weekly summaries reveal it three weeks in. A duplication exploit inflates the economy in an afternoon. A $50,000 creative test on Meta burns its budget before the D1 cohort report arrives. A pricing experiment runs 48 hours when the losing arm was obvious in two.

Every one of these is a windowed aggregation over an event stream, often joined to reference data such as campaign spend, tier thresholds, or experiment assignments. RisingWave maintains them as materialized views that update incrementally as events arrive, serves them over the PostgreSQL protocol to Metabase, Grafana, or Superset, and pushes them to Kafka for liveops automation. RisingWave is open source under Apache 2.0, written in Rust, and checkpoints state to S3.

One Event Stream, Many Views

Studios usually have several telemetry streams: a mobile SDK or Firebase forwarder, a payments service, a battle pass or progression service, an economy service, and MMP attribution postbacks. The pattern below gives each its own source and builds views per team. Player profiles come from the game database through CDC so segments and churn scores can be enriched without a batch export.

CREATE SOURCE player_events (
    event_id            VARCHAR,
    player_id           BIGINT,
    device_id           VARCHAR,
    platform            VARCHAR,     -- 'ios', 'android', 'pc_steam', 'ps5', 'xbox', 'switch'
    app_version         VARCHAR,
    country             VARCHAR,
    channel             VARCHAR,     -- acquisition channel
    session_id          VARCHAR,
    event_type          VARCHAR,     -- 'install', 'session_start', 'session_end', 'tutorial_start', 'tutorial_complete',
                                     -- 'level_complete', 'level_fail', 'quest_abandon', 'purchase', 'first_purchase',
                                     -- 'friend_interact', 'chat_message', 'ad_impression'
    level               INT,
    session_duration_s  INT,
    revenue_usd         NUMERIC(10,4),
    event_time          TIMESTAMPTZ
) WITH (
    connector = 'kafka',
    topic = 'game.player.events',
    properties.bootstrap.server = 'kafka:9092',
    scan.startup.mode = 'latest'
) FORMAT PLAIN ENCODE JSON;

CREATE SOURCE transactions (
    transaction_id  VARCHAR,
    player_id       BIGINT,
    game_id         VARCHAR,
    product_id      VARCHAR,
    product_tier    VARCHAR,         -- 'starter', 'standard', 'premium', 'ultimate'
    usd_amount      NUMERIC,
    platform        VARCHAR,
    region          VARCHAR,
    is_refund       BOOLEAN,
    purchase_time   TIMESTAMPTZ
) WITH (
    connector = 'kafka',
    topic = 'transactions',
    properties.bootstrap.server = 'kafka:9092',
    scan.startup.mode = 'latest'
) FORMAT PLAIN ENCODE JSON;

CREATE TABLE player_profiles (
    player_id            BIGINT PRIMARY KEY,
    country              VARCHAR,
    acquisition_channel  VARCHAR,
    signup_date          DATE,
    vip_tier             INT
) WITH (
    connector = 'postgres-cdc',
    hostname = 'gamedb', port = '5432',
    username = 'rw', password = 'secret',
    database.name = 'gamedb', schema.name = 'public', table.name = 'player_profiles'
);

Live DAU, Sessions, Revenue, and the Onboarding Funnel

Hourly DAU with installs, revenue, and ARPU by platform, country, and version is the view product managers keep open. The daily onboarding funnel below it is the single biggest growth lever: when tutorial completion drops after an update, it shows up the same day.

CREATE MATERIALIZED VIEW dau_live AS
SELECT window_start, window_end, platform, country, app_version,
       COUNT(DISTINCT player_id)                                        AS dau,
       COUNT(DISTINCT session_id)                                       AS sessions,
       COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'install')  AS new_players,
       SUM(revenue_usd)                                                 AS revenue_usd,
       ROUND(SUM(revenue_usd) / NULLIF(COUNT(DISTINCT player_id), 0), 4) AS arpu_usd
FROM TUMBLE(player_events, event_time, INTERVAL '1 HOUR')
GROUP BY window_start, window_end, platform, country, app_version;

CREATE MATERIALIZED VIEW onboarding_funnel AS
SELECT window_start, window_end, channel, country, app_version,
       COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'install')            AS step_install,
       COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'tutorial_start')     AS step_tutorial_start,
       COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'tutorial_complete')  AS step_tutorial_complete,
       COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'first_purchase')     AS step_first_purchase,
       ROUND(COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'tutorial_complete')::DECIMAL
             / NULLIF(COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'install'), 0) * 100, 2) AS tutorial_completion_pct,
       ROUND(COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'first_purchase')::DECIMAL
             / NULLIF(COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'install'), 0) * 100, 2) AS install_to_purchase_pct
FROM TUMBLE(player_events, event_time, INTERVAL '1 DAY')
GROUP BY window_start, window_end, channel, country, app_version;

CREATE MATERIALIZED VIEW revenue_monitor_15m AS
SELECT window_start, window_end, platform, country,
       COUNT(*)                                        AS purchase_count,
       SUM(revenue_usd)                                AS gross_revenue_usd,
       COUNT(*) FILTER (WHERE revenue_usd = 0)         AS zero_revenue_purchases
FROM TUMBLE(player_events, event_time, INTERVAL '15 MINUTES')
WHERE event_type = 'purchase'
GROUP BY window_start, window_end, platform, country;

A spike in zero_revenue_purchases alongside a normal purchase count is a payment gateway recording transactions without collecting money. Fifteen-minute windows catch it before it compounds.

Monetization: ARPPU, Whale Skew, and Product Tiers

ARPPU isolates revenue per paying user. Rising ARPPU with flat DAU means whales are spending more or casual spenders are churning out of the denominator; falling ARPPU after a price change means the new pricing alienated the base. Hourly windows show the effect of a limited-time bundle within the hour; a rolling seven-day view is the trend line, and the gap between mean and median transaction value measures whale dependence.

CREATE MATERIALIZED VIEW arppu_hourly AS
SELECT window_start, window_end, game_id, platform, region,
       COUNT(DISTINCT player_id)                                 AS paying_users,
       SUM(usd_amount) FILTER (WHERE NOT is_refund)              AS gross_revenue,
       SUM(usd_amount) FILTER (WHERE is_refund)                  AS refund_amount,
       ROUND(SUM(usd_amount) FILTER (WHERE NOT is_refund) / NULLIF(COUNT(DISTINCT player_id), 0), 2) AS arppu,
       ROUND(COUNT(*)::NUMERIC / NULLIF(COUNT(DISTINCT player_id), 0), 2) AS transactions_per_payer
FROM TUMBLE(transactions, purchase_time, INTERVAL '1 HOUR')
WHERE usd_amount <> 0
GROUP BY window_start, window_end, game_id, platform, region;

CREATE MATERIALIZED VIEW arppu_rolling_7d AS
SELECT game_id, platform, window_end::DATE AS snapshot_date,
       COUNT(DISTINCT player_id)                                                        AS paying_users_7d,
       SUM(usd_amount)                                                                  AS revenue_7d,
       ROUND(SUM(usd_amount) / NULLIF(COUNT(DISTINCT player_id), 0), 2)                 AS arppu_7d,
       AVG(usd_amount)                                                                  AS avg_transaction_value,
       PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY usd_amount)                          AS median_transaction_value
FROM HOP(transactions, purchase_time, INTERVAL '1 DAY', INTERVAL '7 DAYS')
WHERE usd_amount > 0 AND NOT is_refund
GROUP BY game_id, platform, window_end;

CREATE MATERIALIZED VIEW arppu_by_product_tier AS
SELECT window_start, game_id, product_tier,
       COUNT(DISTINCT player_id) AS buyers, SUM(usd_amount) AS tier_revenue,
       ROUND(SUM(usd_amount) / NULLIF(COUNT(DISTINCT player_id), 0), 2) AS tier_arppu
FROM TUMBLE(transactions, purchase_time, INTERVAL '1 DAY')
WHERE usd_amount > 0 AND NOT is_refund
GROUP BY window_start, game_id, product_tier;

Signals worth watching: iOS ARPPU running 40 percent above Android is audience mix or price sensitivity; ARPPU rising while paying user count falls is extraction from a shrinking base; the rate at which ARPPU decays after a special event tells you whether the event created habitual spenders or just event-motivated ones.

Battle Pass Progression, XP Velocity, and Conversion

A battle pass has a reference table of tier thresholds and an event stream of XP, unlocks, purchases, and claims. The tier funnel shows where players stall, daily XP velocity shows whether the curve or an exploited XP source is the cause, and the purchase view tracks free-to-premium conversion through the season.

CREATE SOURCE battle_pass_events (
    player_id    BIGINT,
    season_id    VARCHAR,
    event_type   VARCHAR,        -- 'xp_earned', 'tier_unlocked', 'pass_purchased', 'reward_claimed'
    tier_number  INT,
    xp_amount    INT,
    is_premium   BOOLEAN,
    event_time   TIMESTAMPTZ
) WITH (
    connector = 'kafka',
    topic = 'battle-pass-events',
    properties.bootstrap.server = 'kafka:9092',
    scan.startup.mode = 'latest'
) FORMAT PLAIN ENCODE JSON;

CREATE TABLE battle_pass_tiers (
    season_id VARCHAR, tier_number INT, xp_required INT, reward_type VARCHAR, is_premium_only BOOLEAN,
    PRIMARY KEY (season_id, tier_number)
);

CREATE MATERIALIZED VIEW tier_progression_funnel AS
SELECT season_id, tier_number,
       COUNT(DISTINCT player_id)                              AS players_at_tier,
       COUNT(DISTINCT player_id) FILTER (WHERE is_premium)    AS premium_players_at_tier,
       COUNT(DISTINCT player_id) FILTER (WHERE NOT is_premium) AS free_players_at_tier
FROM battle_pass_events
WHERE event_type = 'tier_unlocked'
GROUP BY season_id, tier_number;

CREATE MATERIALIZED VIEW xp_velocity_daily AS
SELECT season_id, window_start::DATE AS activity_date,
       COUNT(DISTINCT player_id)                                                 AS active_players,
       SUM(xp_amount)                                                            AS total_xp_earned,
       MAX(xp_amount)                                                            AS max_xp_single_event,
       ROUND(SUM(xp_amount)::NUMERIC / NULLIF(COUNT(DISTINCT player_id), 0), 1)  AS avg_xp_per_player
FROM TUMBLE(battle_pass_events, event_time, INTERVAL '1 DAY')
WHERE event_type = 'xp_earned'
GROUP BY season_id, window_start;

CREATE MATERIALIZED VIEW pass_purchase_metrics AS
SELECT window_start, window_end, season_id,
       COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'pass_purchased')  AS purchases,
       COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'xp_earned')       AS engaged_players,
       ROUND(COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'pass_purchased')::NUMERIC
             / NULLIF(COUNT(DISTINCT player_id) FILTER (WHERE event_type = 'xp_earned'), 0) * 100, 2) AS purchase_conversion_pct
FROM TUMBLE(battle_pass_events, event_time, INTERVAL '1 HOUR')
GROUP BY window_start, window_end, season_id;

A sharp drop between tier 30 and 31 in the funnel is an XP curve problem or a weak reward at that threshold, visible within days rather than at the season postmortem. The xp_velocity_daily view also exposes the weekly engagement pattern, which tells you which days to schedule XP boost events.

Economy Health: Gold Velocity, Price Inflation, and Transfer Networks

A virtual economy breaks when gold is created faster than it is destroyed, when player market prices decouple from designed values, or when farming rings move wealth through account networks. Five-minute velocity windows catch a duplication exploit as it starts; a fifteen-minute price tracker joined to the item catalog measures inflation per item; an hourly transfer view flags networks.

CREATE SOURCE economy_events (
    event_id       VARCHAR,
    player_id      BIGINT,
    event_type     VARCHAR,       -- 'gold_earn', 'gold_spend', 'quest_reward', 'trade', 'craft'
    item_id        VARCHAR,
    quantity       INT,
    gold_delta     BIGINT,
    trade_partner  BIGINT,
    server_id      VARCHAR,
    event_time     TIMESTAMPTZ
) WITH (
    connector = 'kafka',
    topic = 'game.economy.events',
    properties.bootstrap.server = 'kafka:9092',
    scan.startup.mode = 'latest'
) FORMAT PLAIN ENCODE JSON;

CREATE TABLE item_catalog (
    item_id VARCHAR PRIMARY KEY, item_name VARCHAR, item_type VARCHAR, base_gold_value BIGINT, rarity VARCHAR, tradeable BOOLEAN
) WITH (
    connector = 'mysql-cdc',
    hostname = 'mysql.internal', port = '3306',
    username = 'rwuser', password = 'secret',
    database.name = 'game_db', table.name = 'item_catalog'
);

CREATE MATERIALIZED VIEW economy_velocity AS
SELECT window_start, window_end, server_id,
       SUM(gold_delta) FILTER (WHERE gold_delta > 0)        AS gold_created,
       ABS(SUM(gold_delta) FILTER (WHERE gold_delta < 0))   AS gold_destroyed,
       SUM(gold_delta)                                      AS net_gold_change,
       COUNT(DISTINCT player_id) FILTER (WHERE gold_delta > 0) AS active_earners,
       MAX(gold_delta)                                      AS max_single_gain
FROM TUMBLE(economy_events, event_time, INTERVAL '5 MINUTES')
GROUP BY window_start, window_end, server_id;

CREATE MATERIALIZED VIEW item_price_tracker AS
SELECT window_start, window_end, e.item_id, c.item_name, c.rarity, c.base_gold_value,
       COUNT(*)                                         AS trade_volume,
       AVG(e.gold_delta / NULLIF(e.quantity, 0))        AS avg_price_per_unit,
       ROUND((AVG(e.gold_delta / NULLIF(e.quantity, 0)) - c.base_gold_value)::DECIMAL
             / NULLIF(c.base_gold_value, 0) * 100, 2)   AS price_premium_pct
FROM TUMBLE(economy_events, event_time, INTERVAL '15 MINUTES') e
JOIN item_catalog FOR SYSTEM_TIME AS OF NOW() c ON e.item_id = c.item_id
WHERE e.event_type = 'trade' AND e.gold_delta > 0 AND c.tradeable
GROUP BY window_start, window_end, e.item_id, c.item_name, c.rarity, c.base_gold_value
HAVING COUNT(*) >= 5;

CREATE MATERIALIZED VIEW suspicious_transfers AS
SELECT window_start, window_end, player_id,
       COUNT(*) FILTER (WHERE gold_delta < 0)   AS trades_sent,
       COUNT(*) FILTER (WHERE gold_delta > 0)   AS trades_received,
       SUM(gold_delta)                          AS net_trade_gold,
       COUNT(DISTINCT trade_partner)            AS unique_partners
FROM TUMBLE(economy_events, event_time, INTERVAL '1 HOUR')
WHERE event_type = 'trade'
GROUP BY window_start, window_end, player_id
HAVING COUNT(DISTINCT trade_partner) > 20 OR ABS(SUM(gold_delta)) > 1000000;

A max_single_gain beyond anything attainable in normal play is an exploit. A 500 percent premium on a common item is inflation. A player with more than 20 trade partners in an hour is a hub in a farming network. All three go to the economy team's alert topic.

Player Segments and Churn Risk

Segments that update in seconds let liveops trigger an offer in the same session a player crosses a spend threshold, and churn scores that update per session let retention systems act in the session where disengagement begins. Both build on daily per-player stats and a seven-day rolling window, enriched with the CDC profile through a temporal join.

CREATE MATERIALIZED VIEW player_daily_stats AS
SELECT player_id, window_start::DATE AS stat_date,
       COUNT(*) FILTER (WHERE event_type = 'session_start')                  AS sessions,
       AVG(session_duration_s) FILTER (WHERE event_type = 'session_end')     AS avg_session_duration,
       COUNT(*) FILTER (WHERE event_type = 'level_complete')                 AS levels_completed,
       COUNT(*) FILTER (WHERE event_type = 'quest_abandon')                  AS quests_abandoned,
       COUNT(*) FILTER (WHERE event_type = 'friend_interact')                AS social_interactions,
       COUNT(*) FILTER (WHERE event_type = 'purchase')                       AS purchases,
       SUM(revenue_usd)                                                      AS daily_revenue,
       MAX(level)                                                            AS max_level
FROM TUMBLE(player_events, event_time, INTERVAL '1 DAY')
GROUP BY player_id, window_start;

CREATE MATERIALIZED VIEW player_7d AS
SELECT player_id,
       SUM(sessions) AS sessions_7d, AVG(avg_session_duration) AS avg_session_duration_7d,
       SUM(levels_completed) AS levels_completed_7d, SUM(quests_abandoned) AS quests_abandoned_7d,
       SUM(social_interactions) AS social_interactions_7d, SUM(purchases) AS purchases_7d,
       SUM(daily_revenue) AS revenue_7d, MAX(max_level) AS current_level
FROM player_daily_stats
WHERE stat_date >= CURRENT_DATE - INTERVAL '7 DAYS'
GROUP BY player_id;

CREATE MATERIALIZED VIEW player_segments AS
SELECT s.player_id, p.country, p.acquisition_channel, s.revenue_7d, s.sessions_7d, s.current_level,
       CASE WHEN s.revenue_7d >= 100 THEN 'whale'
            WHEN s.revenue_7d >= 20  THEN 'dolphin'
            WHEN s.sessions_7d >= 14 THEN 'highly_engaged_free'
            WHEN s.sessions_7d >= 3  THEN 'casual'
            ELSE 'at_risk' END AS segment
FROM player_7d s
JOIN player_profiles FOR SYSTEM_TIME AS OF NOW() p ON s.player_id = p.player_id;

CREATE MATERIALIZED VIEW churn_risk_scores AS
SELECT player_id, country, vip_tier, acquisition_channel, sessions_7d, avg_session_duration_7d,
       churn_risk_score,
       CASE WHEN sessions_7d = 0 THEN 'lapsed'
            WHEN churn_risk_score >= 60 THEN 'high_risk'
            WHEN churn_risk_score >= 30 THEN 'medium_risk'
            ELSE 'retained' END AS churn_risk_tier
FROM (
    SELECT s.*, p.country, p.vip_tier, p.acquisition_channel,
           LEAST(100,
                 CASE WHEN s.sessions_7d = 0 THEN 50 ELSE 0 END
               + CASE WHEN s.sessions_7d <= 1 THEN 25 ELSE 0 END
               + CASE WHEN s.avg_session_duration_7d < 120 THEN 15 ELSE 0 END
               + CASE WHEN s.levels_completed_7d = 0 THEN 10 ELSE 0 END
               + CASE WHEN s.quests_abandoned_7d > 3 THEN 15 ELSE 0 END
               + CASE WHEN s.social_interactions_7d = 0 THEN 10 ELSE 0 END
               - CASE WHEN s.purchases_7d > 0 THEN 20 ELSE 0 END) AS churn_risk_score
    FROM player_7d s
    JOIN player_profiles FOR SYSTEM_TIME AS OF NOW() p ON s.player_id = p.player_id
) scored;

The weights are a rule-based starting point. Replace them with a trained model once you have labeled churn outcomes; the features stay the same. A retention service consuming the sink dispatches an in-game bonus for high_risk, a push for lapsed, and a guild recommendation for players with zero social interactions.

User Acquisition: Early ROAS and Install Quality

UA runs on compressed cycles. Attribution postbacks from AppsFlyer, Adjust, or Kochava joined to revenue in the first 24 hours after install give hourly ROAS by campaign, network, and creative on launch day, and an install quality tier that can pause low-quality creatives automatically.

CREATE SOURCE attribution_events (
    install_id        VARCHAR,
    player_id         BIGINT,
    campaign_id       VARCHAR,
    ad_network        VARCHAR,
    creative_id       VARCHAR,
    country           VARCHAR,
    platform          VARCHAR,
    install_cost_usd  NUMERIC,
    install_time      TIMESTAMPTZ
) WITH (
    connector = 'kafka',
    topic = 'attribution-postbacks',
    properties.bootstrap.server = 'kafka:9092',
    scan.startup.mode = 'latest'
) FORMAT PLAIN ENCODE JSON;

CREATE MATERIALIZED VIEW campaign_early_roas AS
SELECT a.campaign_id, a.ad_network, a.creative_id, a.country, a.platform, window_start, window_end,
       COUNT(DISTINCT a.player_id)                                             AS installs,
       SUM(a.install_cost_usd)                                                 AS total_spend,
       COALESCE(SUM(t.usd_amount), 0)                                          AS d1_revenue,
       COALESCE(SUM(t.usd_amount), 0) / NULLIF(SUM(a.install_cost_usd), 0)     AS d1_roas,
       SUM(a.install_cost_usd) / NULLIF(COUNT(DISTINCT a.player_id), 0)        AS cpi,
       COUNT(DISTINCT t.player_id)                                             AS paying_players,
       CASE WHEN COALESCE(SUM(t.usd_amount), 0) / NULLIF(COUNT(DISTINCT a.player_id), 0) >= 1.50 THEN 'high_quality'
            WHEN COALESCE(SUM(t.usd_amount), 0) / NULLIF(COUNT(DISTINCT a.player_id), 0) >= 0.30 THEN 'mid_quality'
            ELSE 'low_quality' END                                             AS install_quality_tier
FROM TUMBLE(attribution_events, install_time, INTERVAL '1 HOUR') a
LEFT JOIN transactions t
  ON a.player_id = t.player_id
 AND NOT t.is_refund
 AND t.purchase_time BETWEEN a.install_time AND a.install_time + INTERVAL '24 HOURS'
GROUP BY a.campaign_id, a.ad_network, a.creative_id, a.country, a.platform, window_start, window_end;

A consumer on the sink calls the ad network's API to lower bids or pause a creative when install_quality_tier = 'low_quality' and installs > 100. The same join with a 7-day bound gives D7 ROAS once cohorts age.

Cross-Platform Players

Games shipping on PC, console, and mobile at once need a unified schema normalized before Kafka and an identity map linking platform IDs to one player_id. Players active on more than one platform typically show two to three times the LTV of single-platform players, and finding them in real time lets you target them before they churn.

CREATE MATERIALIZED VIEW cross_platform_players AS
SELECT player_id, window_end::DATE AS snapshot_date,
       COUNT(DISTINCT platform)                                     AS active_platforms,
       ARRAY_AGG(DISTINCT platform)                                 AS platforms_used,
       SUM(revenue_usd)                                             AS spend_30d,
       COUNT(DISTINCT session_id)                                   AS sessions_30d,
       MAX(event_time)                                              AS last_active
FROM HOP(player_events, event_time, INTERVAL '1 DAY', INTERVAL '30 DAYS')
GROUP BY player_id, window_end
HAVING COUNT(DISTINCT platform) > 1;

CREATE MATERIALIZED VIEW feature_usage_by_platform AS
SELECT window_start, platform, event_type AS feature_name,
       COUNT(*) AS usage_count, COUNT(DISTINCT player_id) AS unique_users
FROM TUMBLE(player_events, event_time, INTERVAL '1 HOUR')
WHERE event_type NOT IN ('session_start', 'session_end', 'purchase')
GROUP BY window_start, platform, event_type;

Platform-specific churn (Android players leaving after day 7 at twice the iOS rate), version adoption velocity per platform, and progression parity across platforms all fall out of the same views.

A/B Testing: Per-Variant Metrics and Retention

Experiment assignments live in a table fed by the feature flag system. Joining events to assignments gives live conversion and revenue per variant every hour, and a seven-day hopping window gives retention per variant.

CREATE TABLE experiment_assignments (
    player_id BIGINT, experiment_id VARCHAR, variant VARCHAR, assigned_at TIMESTAMPTZ,
    PRIMARY KEY (player_id, experiment_id)
);

CREATE MATERIALIZED VIEW ab_test_results AS
SELECT ea.experiment_id, ea.variant, window_start, window_end,
       COUNT(DISTINCT pe.player_id)                                                 AS active_players,
       COUNT(*) FILTER (WHERE pe.event_type = 'purchase')                           AS purchase_count,
       SUM(pe.revenue_usd) FILTER (WHERE pe.event_type = 'purchase')                AS total_revenue,
       COUNT(DISTINCT pe.player_id) FILTER (WHERE pe.event_type = 'purchase')       AS converting_players,
       ROUND(COUNT(DISTINCT pe.player_id) FILTER (WHERE pe.event_type = 'purchase')::NUMERIC
             / NULLIF(COUNT(DISTINCT pe.player_id), 0) * 100, 2)                    AS conversion_rate_pct
FROM TUMBLE(player_events, event_time, INTERVAL '1 HOUR') pe
JOIN experiment_assignments ea ON pe.player_id = ea.player_id
WHERE pe.event_time >= ea.assigned_at + INTERVAL '24 HOURS'    -- skip the novelty window
GROUP BY ea.experiment_id, ea.variant, window_start, window_end;

CREATE MATERIALIZED VIEW retention_by_variant AS
SELECT ea.experiment_id, ea.variant, window_end::DATE AS cohort_snapshot, COUNT(DISTINCT pe.player_id) AS retained_players
FROM HOP(player_events, event_time, INTERVAL '1 DAY', INTERVAL '7 DAYS') pe
JOIN experiment_assignments ea ON pe.player_id = ea.player_id
WHERE pe.event_type = 'session_start'
GROUP BY ea.experiment_id, ea.variant, window_end;

RisingWave keeps the counts fresh; significance testing, multiple comparison corrections, and holdout analysis belong in a statistics layer that reads the aggregates. A holdout variant that sees no experiments measures long-term game health independently of ongoing tests.

Serving Dashboards and Liveops Automation

BI tools connect over PostgreSQL and query the views directly, or upsert sinks keep an analytics database current for dashboards that already exist. Kafka sinks drive automation: segment changes to the CRM, churn tiers to the retention service, economy alerts to the ops channel, quality tiers to the UA bidding tool.

CREATE SINK dau_sink FROM dau_live
WITH (connector = 'jdbc', jdbc.url = 'jdbc:postgresql://bi-db:5432/analytics',
      table.name = 'dau_hourly', type = 'upsert', primary_key = 'window_start,platform,country,app_version');

CREATE SINK segments_to_kafka FROM player_segments
WITH (connector = 'kafka', topic = 'player-segments-live', properties.bootstrap.server = 'kafka:9092')
FORMAT UPSERT ENCODE JSON;

CREATE SINK churn_risk_to_kafka FROM churn_risk_scores
WITH (connector = 'kafka', topic = 'churn-risk-live', properties.bootstrap.server = 'kafka:9092')
FORMAT UPSERT ENCODE JSON;

CREATE SINK economy_alerts FROM (SELECT * FROM economy_velocity WHERE max_single_gain > 50000)
WITH (connector = 'kafka', topic = 'game.economy.alerts', properties.bootstrap.server = 'kafka:9092')
FORMAT PLAIN ENCODE JSON;

CREATE SINK ua_quality_alerts FROM (SELECT * FROM campaign_early_roas WHERE install_quality_tier = 'low_quality' AND installs > 100)
WITH (connector = 'kafka', topic = 'ua-quality-alerts', properties.bootstrap.server = 'kafka:9092')
FORMAT UPSERT ENCODE JSON;

CREATE SINK battle_pass_history FROM tier_progression_funnel
WITH (connector = 'iceberg', type = 'append-only', catalog.type = 's3', s3.region = 'us-east-1',
      s3.bucket = 'game-analytics-lake', s3.path = 'battle-pass/tier-funnel/');

The Iceberg sink keeps a durable history for cross-season comparison while RisingWave serves the live queries.

Batch Game Analytics vs Streaming SQL

QuestionNightly batchStreaming SQL (RisingWave)
Is the new onboarding flow broken?Tomorrow's reportSame-day funnel, hourly DAU
Is the flash bundle working?Next dayHourly ARPPU by region and tier
Where are players stalling in the pass?Weekly summaryTier funnel and daily XP velocity, live
Is gold being duplicated?After the economy is damagedFive-minute velocity alert
Who just became a whale or an at-risk player?Next morningSegment flips on the event
Should we pause this creative?D1 cohort report, budget spentHourly ROAS and quality tier on launch day
Which variant is winning?48 hoursHourly per-variant conversion

Frequently Asked Questions

Can one RisingWave cluster serve all of these teams? Yes. Each team's views read from shared sources, and views that build on other views, such as player_7d on player_daily_stats, add little cost. Partition Kafka topics by player_id so per-player aggregations stay local.

How do I handle players on multiple devices or platforms? Resolve identity before Kafka where possible so player_id is canonical. Where it is not, stream the identity map into RisingWave and join it in a view that rewrites platform IDs before the aggregations.

How often do segments and churn tiers change? On every qualifying event. The sinks use upsert encoding, so downstream systems see the current tier per player rather than a stream of duplicates. Add a cooldown join if a notification system needs rate limiting.

Can I replace the rule-based churn score with a model? Yes. Keep player_7d as the feature view, train on labeled outcomes exported from it, and either score in a service that reads the view or call the model from a Python user-defined function inside a view.

How do I backfill history when first deploying? Set scan.startup.mode = 'earliest' on the sources. RisingWave processes retained history first and then continues streaming, so ARPPU trends, funnels, and cohort views start with full history.

The engine for real-time streaming data.
Analyze, search, and decide.
GitHubXLinkedInSlackYouTube
Sign up for our to stay updated.