Analytics & BI · Customer segmentation

Customer segmentation based on purchase history

The pipeline groups customers by how recently they bought, how often they return and how much they spend. Marketing can compare segments and see how each customer’s activity changes over time.

RoleSole Data Engineer
IndustryAutomotive service
ScopePer customer · per year
StackPySpark · PostgreSQL
6loyalty tiers, scored automatically
7activity statuses, refreshed every run
‹X›%lower ad spend (add real number)

The problem

Marketing paid the same for everyone

Campaigns were one-size-fits-all: the same offer and the same budget reached a brand-new customer and a ten-year loyal one. There was no way to see who's valuable, who's slipping, and who's already gone.

What RFM means

Three simple questions about every customer

R

Recency

How recently did they last come in? Days since their last service visit — the fresher, the more engaged.

F

Frequency

How often do they come back? Total service visits over their whole lifetime with the network.

M

Monetary

How much do they spend? Total spend on works and parts, converted to a stable USD base.

What I built

A pipeline that scores and labels every customer

From the network's service history I compute Recency, Frequency and Monetary value for every customer, for every year of their lifetime. Each customer is ranked against their true peers, the ranks are normalized into one comparable 0–1 loyalty score, and from that score they get a loyalty tier and an activity status.

Because it runs per customer, per year, the output isn't a one-off snapshot — it's a trajectory. You see exactly when someone starts slipping.

Source — service history (visits · parts · works)
1–3
R / F / M metricsPer customer, per year — plus USD conversion & derived metrics
4
Rank & normalizeRanked vs peers, min-max normalized to one 0–1 score
5
Loyalty tierPlatinum · Gold · Silver · Bronze · Prospect · Dormant
6
Activity statusActive · Declining · At risk · Churned …
Per-customer Power BIEvery customer, tiered and tracked

Why my approach works

Scores recalculated against customer peers

The model ranks customers within their peer groups and normalizes the ranks into a comparable score. Annual recalculation makes it possible to compare a customer’s position over time.

The result

Every customer, tiered and tracked

Marketing opens one dashboard and sees the whole base by loyalty tier and activity status — and can drill to any single customer. (Distribution shown is illustrative.)

Customer segmentation · RFM overview refreshed yearly
Loyalty tiers (by RFM score)
Platinum
5% · 0.95–1.0
Gold
14% · 0.75–0.95
Silver
22% · 0.55–0.75
Bronze
26% · 0.30–0.55
Prospect
19% · 0.15–0.30
Dormant
14% · 0.00–0.15
Activity status
Active New Declining At risk Reactivated Won back Churned
Client #146853 · Private · Toyota · since 2017
A Platinum customer who's quietly cooling off
Platinum Declining
0.88R
1.00F
1.00M

Down to one customer

One customer's full RFM journey — year by year

The customer view shows the tier, activity status and RFM components for each year. Marketing can use a decline in the score as a reason to review the relationship and plan a follow-up.

Client #146853 · Private · Toyota10 years of history
YearVisitsTotal $Loyalty tierActivityRatingRating Δ
20174$688SilverNew0.650.0%
20189$1,969GoldActive0.900.0%
20198$3,398GoldActive0.950.0%
202011$4,837GoldActive0.950.0%
20216$5,878PlatinumActive1.000.0%
20224$7,616PlatinumDeclining0.95−3.5%
20238$8,925PlatinumActive0.95−1.3%
20246$10,696PlatinumActive0.95−1.4%
20255$12,759PlatinumActive1.00−0.3%
20261$13,333PlatinumDeclining0.95−1.8%

This customer climbed from Silver to Platinum in four years, dipped in 2022 (−3.5%), recovered, and is cooling again now. Every turn was flagged the year it happened — months before a churn report would notice.

Loyalty rating — catch the decline, don't lose them
Loyalty rating (0–1) Declining — react now If ignored → churn
R / F / M components over time
Recency Frequency Monetary
Lifetime service visits
Cumulative visits — 62 over the lifetime
Lifetime spend (USD)
Cumulative spend — $13,333 lifetime

The amber points are the moment to act: the customer is Declining but still recoverable. Ignore them and the same person slides to Churned — when winning them back costs far more. The whole value is reacting in the amber zone, not the red one.

The point

Different offers for different customer groups

Tier and activity status help marketing choose whom to contact and what to offer. The segments provide a basis for campaigns; their results still need to be measured.

GroupWhat it meansMarketing playAd spend
Platinum · ActiveYour best, fully engaged customersVIP perks & loyalty care≈ none needed
Gold / Silver · DecliningValuable customers starting to slipTargeted win-back offer — the high-ROI movefocus here
Bronze · NewRecent customers worth growingOnboarding nudge, next-service reminderlow
Dormant / ChurnedAlready gone or never engagedOne low-cost reactivation — then stopminimal

Built to be trusted

How scores are checked

  Fair, stable, validated

  • USD-normalized spend — monetary value is converted to a stable base, so currency swings don't reshuffle the rankings.
  • Recency capped — extreme gaps are clamped (5 years) so outliers can't distort the normalized score.
  • Per-customer dedup — every visit is tied to one customer identity before scoring.
  • Telegram alerts & Apache Airflow — orchestrated, monitored, refreshed reliably.

The outcome

Customer groups for campaign planning

Before

  • Same offer & budget for everyone
  • Churn noticed only after it happened
  • No per-customer value or loyalty view
  • Ad budget sprayed across the whole base

After

  • Every customer scored, tiered & tracked
  • Declines flagged the moment they start
  • A clear playbook per group
  • Promos only where they pay off — less wasted spend

Quantified business results (ad-spend reduction, retention lift) — add real numbers.

Stack & role

How it's built

Sole data engineer — metric design, scoring logic, data-quality and deployment.

Apache SparkPySparkSpark SQL window functionsApache AirflowPostgreSQLPower BITelegram alerts

Spending the same on every customer?

We can group your customers by purchase history and prepare segments your marketing team can use for campaigns.

Discuss your project →