Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

ScalaadvancedaiAI generated

Real-Time Stock Price Stream Processor

Build a streaming system in Scala that processes live stock price ticks as they arrive: for each symbol it keeps rolling averages and volatility over recent windows, flags sudden price spikes as anomalies, and streams the live results to browsers over Server-Sent Events. It's built with Akka Streams, which handles backpressure automatically, so when the system can't keep up, the source slows down instead of memory filling up. Note that Akka now uses a commercial license for newer versions; Apache Pekko is a free, API-compatible fork you can use instead. A simulator generates realistic ticks so you can test at any speed. You'll learn stream graphs, per-key processing, sliding windows, simple anomaly detection, SSE with Akka HTTP, and measuring throughput and latency.

Estimate
~15h
Steps
7
Completed by
0
Proposed by
codeseed.app

Akka/Pekko Streams · Akka/Pekko HTTP

Project roadmap

  1. 01

    Simulate ticks

    ~2h

    Create an sbt project with Akka Streams and Akka HTTP (or Pekko). Define a Tick case class (symbol, price, volume, timestamp). Build a Source that emits ticks for 20 symbols at a configurable rate, with prices following a random walk and occasional injected spikes, recorded so you can later check they're detected. Done when: the source prints realistic ticks at the chosen rate.

  2. 02

    Build the stream graph

    ~2.5h

    Build the pipeline: validate ticks (drop and count invalid ones), split the stream per symbol with groupBy, run the per-symbol processing, merge the results, and send them to a sink. Add buffers with explicit overflow strategies where needed and log throughput. Done when: ticks flow through the graph, and throughput is logged.

  3. 03

    Compute rolling statistics

    ~2.5h

    For each symbol, use statefulMap (or scan) to keep a sliding window of the last N ticks (or last T seconds), updating the moving average and the standard deviation of returns (volatility) incrementally rather than recalculating from scratch. Emit an update per tick. Done when: the statistics match a batch calculation over the same ticks.

  4. 04

    Detect anomalies

    ~2h

    Flag a tick as an anomaly when its price is more than K standard deviations from the rolling average (a z-score), after a warm-up period. Also avoid repeated alerts for the same spike with a cooldown. Send anomalies to a separate output. Done when: the injected spikes are detected, with few false alarms at a sensible K.

  5. 05

    Stream results over HTTP

    ~2h

    Add Akka HTTP routes: GET /stream/{symbol} and GET /anomalies returning Server-Sent Events, fed through a BroadcastHub so many clients can subscribe to the live stream, and GET /snapshot with the latest statistics for all symbols. A slow client must not slow down the pipeline (drop old messages for that client). Write a small HTML page showing a live chart. Done when: several browser tabs show live updates at the same time.

  6. 06

    Load test and tune

    ~2h

    Increase the simulator's rate step by step, measuring ticks per second and the time from tick to result, and watch where backpressure appears. Tune buffer sizes and parallelism, and document the results and the bottleneck in README.md. Done when: README.md shows maximum throughput and latency, and how they changed with tuning.

  7. 07

    Test it

    ~2h

    Write tests with Akka Streams TestKit (TestSource and TestSink): rolling statistics on known sequences, anomaly detection with warm-up and cooldown, invalid ticks dropped, per-symbol separation, and backpressure (the sink requesting slowly). Done when: sbt test passes.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~15h · 7 steps

Tech stack

Akka/Pekko StreamsAkka/Pekko HTTP