Problem
Vinted is a C2C marketplace with almost 600 million unique items. With ordinary filters, a user can pick a colour that has no items in the current results and land on an empty page. Faceted search fixes this by showing only the options present in the results, with a count next to each. At Vinted this had to work for colours, sizes and brands with a 99.9% success rate, P99 latency under 150 ms and more than 2,000 search requests per second. The catalog changes with every upload and sale, so counts go stale quickly.
Example from the article: a search returns 6 items in various colours. A standard filter lists all colours, and clicking "Orange" gives zero results. The facet lists only the colours that exist, each with its item count.
Solution in brief
Run facet aggregations as separate Elasticsearch requests, one per facet, and make each one cheap: no hits, a document limit per shard, fewer brand values and buckets. Exclude a facet's own filter from its request, so multi-select works. Cache the responses in Memcached for a time that depends on how many items the query matches.
Questions this case answers
- How to compute per-filter value counts for a ranked query at high request rate within a strict tail-latency budget when the catalog changes constantly
- How to keep filter counts correct for multi-select filters where the selected values of a filter must not shrink that filter's own options
- How to show filter options with item counts that match the current search results, so a click never leads to zero results?
- How to keep facet requests under 150 ms P99 at more than 2,000 search requests per second on Elasticsearch?
Tools and methods
- Elasticsearch terms aggregation — counts items per colour, size and brand
- Memcached — stores facet responses, with a cache time based on result size
- terminate_after and size parameters — cap the work done per facet request
Google or a one-time email code. No password.