Skip to main content

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!

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!