š Uber - Surge Pricing Service
Real-time Pricing Based on Demand & Supply
Project Overview
Real-time Pricing Based on Demand & Supply
Uber wants to optimize its surge pricing algorithm to balance ride demand and driver availability in real-time. Your task is to build a Surge Pricing Microservice that calculates and returns a surge multiplier for ride fares based on demand and supply conditions in a specific location.
This service will be queried by the Ride Request Service to determine the appropriate fare adjustments during peak hours or high-demand situations.
Read the uber project microservices overview beforehand to understand how this fits in the architecture of the entire microservice.
Your submissions
No submissions yet, start by making your first submission
Detailed Project Description
Read the uber project microservices overview beforehand to understand how this fits in the architecture of the entire microservice.
šÆ Key Objectives
- Your API should run on the port 5001.
- Build an API that calculates and returns a surge multiplier based on active ride requests and available drivers.
- Ensure real-time pricing updates by dynamically adjusting surge values.
- Integrate with other microservices (Ride Request, Driver Management) to fetch required data.
- Implement a logic-driven pricing model to ensure fairness and prevent price abuse.
š Required API Endpoints
Your Surge Pricing Service API should expose the following endpoints:
1ļøā£ Get Surge Multiplier for a Location
- Endpoint:
GET /surge?lat={lat}&lng={lng}
- Description: Returns the surge multiplier for the given location.
- Request Parameters:
lat
(float) ā Latitude of the location.lng
(float) ā Longitude of the location.
- Response:
{ "location": { "lat": 40.7128, "lng": -74.006 }, "activeRequests": 15, "availableDrivers": 5, "surge_multiplier": 2.0 }
- Logic:
- If available drivers = 0, return maximum surge multiplier (e.g.,
2.5
). - If demand/supply ratio ⤠1, return 1.0 (no surge).
- If demand/supply ratio > 1.5, increase the multiplier gradually (e.g.,
1.2, 1.5, 2.0
). - Ensure the multiplier never exceeds a maximum cap to prevent extreme pricing.
- If available drivers = 0, return maximum surge multiplier (e.g.,
āļø How the Surge Pricing Logic Works
-
Tracking Demand & Supply:
- The system monitors active ride requests and available drivers in real-time.
- Data is stored per geographical location (lat, lng).
-
Calculating Surge Multiplier:
- Demand-Supply Ratio =
active ride requests / available drivers
- If supply is low, increase the multiplier.
- If supply is high, keep the multiplier at 1.0 (no surge).
- Demand-Supply Ratio =
-
Integration with Ride Request Service:
- When a user requests a ride, the Ride Request Service queries this service.
- The multiplier is applied to the fare calculation to adjust pricing.
š Expected Behavior
Scenario | Expected Surge Multiplier |
---|---|
Low demand, many drivers | 1.0 (No surge) |
Moderate demand, balanced drivers | 1.2 - 1.5 (Mild surge) |
High demand, few drivers | 2.0 (Strong surge) |
No available drivers | 2.5 (Max Surge) |
š Deliverables
- A fully functional Surge Pricing API with the defined endpoints.
- Proper logic implementation for surge calculations.
- Well-structured error handling and validations.
- Your API should run on the port 5001.
š By completing this project, you will create a real-world, scalable surge pricing engine used in ride-sharing applications like Uber! šš”
Project Completion Criteria
- The system should allow users to retrieve a surge multiplier for a given location via the GET /surge?lat={lat}&lng={lng} endpoint.
- The system should dynamically calculate surge pricing based on the ratio of active ride requests to available drivers.
- The system should ensure that if no drivers are available, the maximum surge multiplier is applied (e.g., 2.5).
- The system should return a surge multiplier of 1.0 when demand and supply are balanced.