Sitemap
Myntra Engineering

Stories of code.

Follow publication

Optimizing Myntra’s Pricing System for Serving Millions of Traffic under 30ms Latency

9 min readFeb 6, 2023

--

Overview

Pricing System Architecture

Pricing System Architecture

Discount Fulfilment Service Scaling

Solutions Considered for Sequential Synchronous Redis & Too Many Network Calls

Redis calls can be made in two ways:-

With Queueing : futures.add(customRedisBatchExecutor.hgetall(productDetailsCacheKey, CommandBatching.queue()))
With Flushing : futures.add(customRedisBatchExecutor.hgetall(productDetailsCacheKey, CommandBatching.flush()))
/* Defining an interface which is extending Commands interface and including
** all necessary methods required to make Redis Calls.
*/
@BatchSize(50)
public interface RedisBatchExecutor extends Commands {
RedisFuture<Map<String, String>> hgetall(String key, CommandBatching commandBatching);
RedisFuture<Boolean> hset(String key, String field, String value, CommandBatching commandBatching);
// .. so on
}

// Object Creation using RedisCommandFactory
RedisCommandFactory redisCommandFactory = new RedisCommandFactory(redisClusterConnection);
RedisBatchExecutor redisBatchExecutor = redisCommandFactory.getCommands(RedisBatchExecutor.class);

// Invoking Redis Calls using the created object

// With Queueing :-
futures.add(customRedisBatchExecutor.hgetall(key, CommandBatching.queue()))

// With Flushing :-
futures.add(customRedisBatchExecutor.hgetall(key, CommandBatching.flush()))

Redis Key & Mongo Document Structure

The Discount Fulfilment Service stores discount data for each product using a 
Redis hash. An example of this is for product id 1000 with seller id 100 and
101, the corresponding Redis key and value would be :-

Key :- discount/1000
Value :-
1) {"key":"sellerId", "value":100}
2) {"mrp":2000, "discountId":140823004, "discountPercent":20%, "discountedAmount":1600, … so on}
3) {"key":"sellerId", "value":101}
4) {"mrp":2000, "discountId":140823005, "discountPercent":30%, "discountedAmount":1400, … so on}
{"productId":1000, "sellerId":100, "mrp":2000, "discountId":140823004, "discountPercent":20%, "discountedAmount":1600, … so on}
{"productId":1000, "sellerId":101, "mrp":2000, "discountId":140823005, "discountPercent":30%, "discountedAmount":1400, … so on}

--

--

Responses (7)