# Incentives Engine   ## Problem Statement Imagine a cab aggregator service that works with several ***Agents*** to enlist independent ***Drivers*** and other smaller ***Cab Companies*** providing us a fixed no.of drivers. Each of these *agents*, *drivers* and *cab companies* are given incentives and milestones to reach. You will be building a system that 1. Gathers business rules for giving incentives. 2. Calculates incentives in ***real time*** for each agent, driver and cab company. 3. Generates pay-out instructions every month.   --- **Stretch goal**: This system should provide a complete audit trail of the incentives given, so that the agents, drivers, cab companies can verify the incentives given to them. And the business has a trail of incentives given to an entity over time. ---   ## Business Rules The business can provide various rules to incentivize favorable activities. The rules can be simple or complex. The system built should provide flexibility to business to express different kinds of business rules in an intuitive and easy manner. Some example rules: - 500 points are given to an agent for every driver enlisted. - 5000 points are given to an agent if a cab company is enlisted with a fixed committed no.of drivers. 250 points will be given for each committed driver from this company. - Agents will be given an additional 2000 points as soon as they reach 50,000 points in a month. - Agents will be given an additional 3000 points as soon as they reach 100,000 points in a month. - Agents will be given additional 1000 points for every 30 drivers they onboard. - For drivers enlisted within the last 3 months, if their average rating for their last 10 rides in 4* or above, the Agent is awarded 500 points. - 700 points will be deducted from an agent if a driver they enlisted drops off within the first week. - 7000 points will be deducted from an agents if a cab company they enlisted drops off within the first month. 300 points will be additionally deducted for every committed driver from this company. - 200 points will be given to the agents for every 10kms successfully driven by their enlisted driver in their first 3 months if that ride received a 4* or above rating. - 10000 points will be given if the agent is the top performer in their region for the current month and 5000 points if they are the second top performer.   There are different kinds of rules here. Although the above examples are only for the *Agents*, the system should be flexible to create similar rules for *drivers* and *cab companies*. The above business rules are ***only indicative examples***. Your system should provide a way to keep adding, deleting or modifying such rules. You can iteratively build your system to accommodate increasing complexity of the rules.   ## Audit Trail *[stretch goal]* The exact aspects that can be audited and traced in this incentive system, will be left as an exercise to you. Its intention will be to provide verifiability of the incentive calculations to both the incentive receiver and the business.   ## Expected Output We’ll be looking forward to the below 3 outputs: - **High Level Design** of the system for the above problem statement. - **Data Model** Calling out the nature of the data store used (sql, nosql), the complete schema and the indexes for each data store. - **API Definition** The Request and Response details for the APIs exposed by each sub-system in your design.   --- **NOTE** : 1. It is not expected that you fully solve this problem statement. Go as far as you can go. 2. You will be focusing only on the backend services and it’s APIs to power this use case. No UI is expected. 3. Focus is only on the incentive engine. There will be many other services that we are not bothered about. 4. No engineering involvement should be required for creating and running new rules. Business should be able to add / modify rules by themselves. ---