Jainam Gala

ETL case study · Spark · Postgres

Real-Time E-Commerce Analytics Pipeline

All 536,639 cleaned sales lines streamed through Spark into Parquet and Postgres with none lost. Postgres revenue matched the source file to the penny, and new data reached the table in about 1 second.

← Back to Portfolio

Summary

The data shows a business that depends on UK customers and on the September to November season. Its headline returns figure is inflated by fees and order-entry errors.

Pipeline results

One full run on a 2-core machine, using the folder source.

MeasureResult
Events streamed536,639 in 107 s (5,000 per second)
Events saved to Parquet536,639 (100%)
Order lines in Postgres536,639 (100%)
Sales revenue, Postgres vs source£10,642,110.80 vs £10,642,110.80
Time from event sent to row in Postgresmedian 1.1 s, 95th percentile 1.7 s, worst 6.0 s (Spark warm-up)
Spark speed per batchabout 9,000 rows per second
Rows in the hourly table4,944 country-hours across 38 countries
Event to Postgres row Median 1.1 s 95th percentile 1.7 s Worst, warm-up 6.0 s
Scale is 0 to 6 seconds. The warm-up is the outlier. The typical row lands in just over a second.

Data quality

CheckRows
Raw rows541,909
Exact duplicates removed5,268
Negative-price adjustments removed2
Rows kept536,639
Missing customer ID (kept, flagged)135,035 (25%)
Return lines (kept, flagged)10,587
Rows kept after cleaning 536,639 kept The orange sliver is 5,270 removed rows, 0.97% of the raw file. 5,268 of those were exact duplicates. Two were negative-price adjustments.
Almost every raw row stayed. The rows that left were nearly all exact duplicates.

Business findings

1. The UK is 85% of revenue

£9.0M of £10.6M in sales. The next markets are the Netherlands (2.7%), Ireland (2.7%), Germany (2.1%) and France (2.0%).

85% UK
  • United Kingdom, 85%, £9.0M
  • Netherlands, 2.7%
  • Ireland, 2.7%
  • Germany, 2.1%
  • France, 2.0%
  • Other markets, 5.5%
Other markets are the remainder after the five named countries. Export markets are real, and they are still a small slice of the £10.6M.

2. Sales nearly double in the autumn

September to November 2011 averaged £1.24M a month, against £684K a month from January to August. November alone was £1.50M.

£0 £0.75M £1.50M £684K Jan–Aug monthly average £1.24M Sep–Nov monthly average November £1.50M
Column height is monthly sales. Autumn demand runs about 1.8 times January to August.

3. Orders arrive in office hours on weekdays

74% of revenue comes between 10:00 and 16:00. Tuesday and Thursday are the biggest days, about 20% each. There are no Saturday sales in the data.

When the revenue arrives 74% 00:00 10:00 16:00 24:00
The dark block is six office hours. It holds 74% of revenue. Saturday has no sales in this file. Tuesday and Thursday are about 20% of revenue each. The other weekdays are not broken out here.

4. The returns figure is misleading

Returns total £894K, 8.4% of sales, but most of that is not customers returning products.

Part of the returns figureValue
Fees and manual adjustments (Amazon fees £235K, manual £147K, postage and others)£418K
Two order-entry errors, each ordered and cancelled the same day (80,995 and 74,215 units)£246K
Product returns£230K, about 2% of product sales
£894K returns, split three ways £418K £246K £230K Fees and adjustments Order-entry errors Product returns
Each slice is its share of the £894K. Product returns are the smallest slice, about 2% of product sales.

5. A quarter of order lines have no customer ID

These lines carry 16.5% of revenue. They cannot be used for customer-level analysis such as repeat purchase or churn.

25% of lines No customer ID 135,035 lines 16.5% of revenue Same lines smaller share of £
A quarter of lines lack a customer ID, and those lines are 16.5% of revenue. The ring is that share. The pale part is lines, or revenue, that can be tied to a customer.

Recommendations

For the business

  1. Plan stock and staffing for September to November. Demand runs about 1.8 times higher than the rest of the year.
  2. Report product returns separately from fees and adjustments. The real product return rate is about 2%, not 8.4%.
  3. Add a check for unusually large orders. Two keying errors moved £246K in and out of the books.
  4. Capture a customer ID on every order. It would make 16.5% more revenue usable for customer analysis.
  5. Test growth outside the UK. The Netherlands, Ireland and Germany are already the largest export markets.

For the pipeline

  1. Split the gold table's returns column into product returns and adjustments.
  2. Benchmark the Kafka path. This run used the folder source.
  3. Add a Grafana dashboard on the Postgres table.
  4. Add automatic tests for row counts and revenue reconciliation.
  5. Use an exact distinct count for invoices. The current count is approximate.

Limits

The measured path is the folder source into Spark, then Parquet and Postgres. Kafka is in the design and is not part of these timings.

Project resources

View GitHub repository
← Back to Portfolio