Sells - Appointments (amount, qty, type of products, agent name, agent id)
Commissions - we are storing commissions for each appointment, each agent (agentid, agent name, appoint details, item details) Payouts - sparse collection - monthly payout records
Each agent - Sum of commissions - sum of payouts
Advantage of CRON - We can deal with long exec times!
How this collection is created:
- (For past records) We created this on a cron BUT on an appointment basis
- (For future records) trigger on sell completion
I/P Date, Page Size
- Find all distinct agents in commissions collection
- Limit
- Gram first n 4 Unwind
- Group on the collection by item 6, Sum
- Get all commissions
Problem: Num of document is same as number of documents in sell Net result: No advantages for this collection
Ex: If an agent has 20,000 appointments - we are dealing with 20,000 records Ex: x 50 num of agents 1,000,000
I/P Date, Page Size
How this collection is created:
- (For past records) We created this on a cron on a date basis
- (For future records) We will create this on a cron on a date basis
Date, Page Size (no change)
- Find all distinct agents in commissions collection
- Limit
- Gram first n 4 Unwind
- Group on the collection by item (This data will be manifold smaller) 6, Sum
- Get all commissions
Ex. If an agent has 20,000 appointments over 365- we are dealing with 365 records Ex. x 50 num of agents = 18250 records
Advantage: 1000000/18250 = 54x
Same as approach 2, with some optimizations
I/P Date, Page Size
- Store all tier pricings in the commissions collection (t1, t2, t3)
- Calculate the tier while doing a payout, and then choose from t1, t2 or t3
How this collection is created (more logic):
- (For past records) We created this on a cron on a weekly basis
- (For future records) We will create this on a cron on a weekly basis
- CRON will run daily
- Based on the current week - It will either
- Create a new document, or,
- Update the existing week document
Date, Page Size (no change)
- Find all distinct agents in commissions collection
- Limit
- Gram first n
- Unwind
- Group on the collection by item (This data will be manifold smaller) 6, Sum
- Get all commissions
Ex. If an agent has 20,000 appointments over 365- we are dealing with 365/7 records Ex. x 50 num of agents = 2600 records
Advantage: 1000000/18250/7 = 54x*7 = 378x improvement