ExDataSketch ships with production-oriented Livebooks that demonstrate real-world usage patterns. Each Livebook is self-contained and executable, requiring only Mix.install([{:ex_data_sketch, "~> 0.9.0"}]) plus any integration dependencies noted below.

The Livebooks are designed to build knowledge incrementally. The recommended reading order is:

  1. Streaming Cardinality -- Start here. Covers from_enumerable/2, ExDataSketch.Stream, Collectable, precision tradeoffs, and ULL vs HLL comparison. No extra dependencies.

  2. Persistence Snapshots -- How to save, load, and merge sketches using ETS, DETS, and binary serialization. No extra dependencies.

  3. Distributed Merges -- Associativity, commutativity, tree aggregation, and ETS-sharded patterns. No extra dependencies.

  4. Rolling Telemetry -- Time-windowed sketch accumulation, persistence, and :telemetry event attachment. No extra dependencies.

  5. Broadway Integration -- accumulate/3, accumulate_into/3, PeriodicAggregator. Requires :broadway.

  6. GenStage Aggregation -- SketchConsumer, SketchProducer, flushing, and callbacks. No extra dependencies.

  7. LiveDashboard Integration -- Wiring :telemetry events into Phoenix LiveDashboard metrics. No extra dependencies (Phoenix patterns are documented in comments).

  8. Phoenix Observability -- Endpoint cardinality, latency percentiles, Theta set difference, ETS persistence, memory comparison. No extra dependencies.

  9. AI Token Stream Analytics -- Multi-dimensional dashboard combining HLL, ULL, DDSketch, MisraGries, CMS, and Bloom for LLM workload monitoring. No extra dependencies.

What Each Livebook Teaches

LivebookCore APIKey Concept
Streaming CardinalityStream.hll, reduce_into, reduce_partitioned, CollectableLazy stream consumption, precision/memory tradeoff
Persistence SnapshotsStorage.ETS.save/load/merge, Storage.DETS, serialize/1Durability hierarchy, EXSK v2 binary format
Distributed Mergesmerge_many/1, merge/2, Storage.ETS.merge/3Associativity, commutativity, tree aggregation
Rolling TelemetryTelemetry.execute, Telemetry.span, GenServer timerTime-windowed aggregation, periodic flush
Broadway IntegrationExDataSketch.Broadway.accumulate/3, ExDataSketch.Broadway.PeriodicAggregatorBatch aggregation, periodic flush, partition handling
GenStage AggregationSketchConsumer, SketchProducer, flush/1Back-pressure, push-based accumulation, callbacks
LiveDashboard IntegrationTelemetry.event_name, all_event_names, :telemetry.attachPhoenix metrics wiring, custom dashboard pages
Phoenix ObservabilityHLL, REQ, CMS, Theta, ETSPer-endpoint DAU, latency distributions, rate limiting
AI Token AnalyticsHLL, ULL, DDSketch, KLL, MisraGries, CMS, BloomMulti-dimensional sketch dashboard

Running a Livebook

# From the project root
livebook open livebooks/streaming_cardinality.livemd

# Or start Livebook and navigate to the livebooks/ directory
livebook server

Each Livebook begins with a Mix.install cell that fetches the required dependencies. The Broadway Livebook additionally installs :broadway.

Livebook Listing

FileTopicLines
streaming_cardinality.livemdStream/Collectable API, precision, ULL vs HLL126
persistence_snapshots.livemdETS, DETS, serialization, multi-backend152
distributed_merges.livemdAssociativity, tree aggregation, ETS sharding121
rolling_telemetry.livemdTime windows, GenServer, telemetry events119
broadway_integration.livemdBatch accumulation, PeriodicAggregator130
genstage_aggregation.livemdSketchConsumer, SketchProducer, flushing172
livedashboard_integration.livemdTelemetry wiring, custom pages, events190
phoenix_observability.livemdDAU, latency, rate limiting, ETS persistence263
ai_token_analytics.livemdLLM workload monitoring, multi-sketch dashboard192