Skip to main content
Solved

Building a Custom Segmentation Engine Inspired by Klaviyo

  • April 21, 2025
  • 1 reply
  • 47 views

Forum|alt.badge.img

Hey Klaviyo community! 👋

I'm currently building a custom segmentation engine for Shopify-based e-commerce customers — something similar to what Klaviyo offers with its rule-based dynamic segments. I’ve gone through the Segment API Guide and understood how flexible and powerful Klaviyo’s segmentation is.

Right now, I'm trying to design a backend structure that can support conditions across multiple models (like customers, orders, products, etc.) with operators like within_last_days, contains, gte, and more.

Before I go too deep into implementation, I’d love to know from you:
🔹 How does Klaviyo optimize segment recalculations for large datasets?
🔹 Any recommendations on caching strategies or batch evaluations vs real-time evaluations?
🔹 If you’ve built something similar, how did you manage parsing user-created conditions into efficient queries?

Would love to hear your thoughts or any best practices. Thanks in advance!

Best answer by MANSIR2094

Hi,

if I can get you right you are building a system to categorize specific conditions just like how klaviyo does it with dynamic segments, this is a possible way you can approach this: Use pre calculated segments and update only when data changes like "new order"

Cache common segment results in memory e.g Redis"to speed up retrieval and you also have to consider batch updates for large datasets and also make use of parameterized queries and indexes e.g on order dates to handle user conditions.

 

Hope this helps!

1 reply

MANSIR2094
Expert Problem Solver IV
Forum|alt.badge.img+20
  • Expert Problem Solver IV
  • Answer
  • April 22, 2025

Hi,

if I can get you right you are building a system to categorize specific conditions just like how klaviyo does it with dynamic segments, this is a possible way you can approach this: Use pre calculated segments and update only when data changes like "new order"

Cache common segment results in memory e.g Redis"to speed up retrieval and you also have to consider batch updates for large datasets and also make use of parameterized queries and indexes e.g on order dates to handle user conditions.

 

Hope this helps!