Calculate Real Time Daily GMV With Apache Beam

Veli Can Ünal7 Jan 2023

Problem

Trendyol's dashboard metrics came from a batch processing system. Fresh data matters for decisions, so the team tried real-time streaming. The first metric they moved was daily gross merchandise volume (GMV).

Example from the article: a Firebase-connected dashboard shows stakeholders real-time daily GMV, with the total refreshed every 10 seconds.

Solution in brief

An Apache Beam pipeline reads order events from Kafka, keeps orders with status "Created" and sums their total price in a one-day calendar window. The window follows local midnight and a repeating trigger fires every 10 seconds, so the running total for the day is written to Firebase and read by the dashboard.

Questions this case answers
  • How to keep a cumulative per-day business metric fresh from an event stream when existing reporting runs only as batch jobs
  • How to show a daily business metric such as gross merchandise volume (GMV) in near real time instead of after a batch run?
  • How to compute a running total that restarts at local midnight over a stream of order events?
  • How to push a continuously updated aggregate to a stakeholder dashboard?

Tools and methods

  • Apache Kafka — source topic with order events
  • Apache Beam (Java SDK) — pipeline: parse, filter, window, aggregate
  • Calendar window — daily window that renews itself at midnight in a chosen time zone
  • Cloud function and Firebase — write the aggregate and feed the dashboard
Continue reading — it's free

Google or a one-time email code. No password.