Implementing AI-Powered Dynamic Pricing in Mobile Applications
Dynamic pricing isn't "raise prices when demand is high." It's an algorithm that continuously balances revenue maximization with conversion preservation. Too aggressive and it erodes trust; too conservative and you leave money on the table.
In mobile apps, this has an extra dimension: the price shown to a user must be consistent within a session. Users shouldn't see the price change between viewing a product card and the checkout screen.
Where and how it applies
E-commerce and marketplaces
Classic scenarios: flight tickets, hotel rooms, delivery, ride-sharing. Price-affecting factors: current demand (active sessions on this item), inventory level, time until offer expiry, competitor prices (public price scraping), user segment.
Pricing models
Three main approaches in order of complexity:
Rule-based: "if stock < 5 units, add 15% to base price." Fast to implement, easy to explain to business, poor at adapting to complex demand patterns.
Regression/ML: a model predicts optimal price from a feature vector. XGBoost with demand, time, and competition features gives good baseline accuracy.
Reinforcement Learning: an agent learns in the environment, receiving rewards for conversion and/or revenue. Harder to implement and debug, but better at long-term optimization. Suited to mature products with high traffic.
Key technical considerations
Price consistency within session
Price is locked on first product view and stays the same until session end (or a defined TTL). Implement via server-side price cache keyed on {user_id}_{item_id}_{session_id}.
// Android: price retrieval with session-level caching
class PricingRepository(
private val pricingApi: PricingApi,
private val sessionId: String
) {
private val priceCache = HashMap<String, PricedItem>()
suspend fun getPrice(itemId: String, userId: String): PricedItem {
// check local session cache first
priceCache[itemId]?.let { return it }
val priced = pricingApi.getPrice(
PriceRequest(
itemId = itemId,
userId = userId,
sessionId = sessionId,
timestamp = System.currentTimeMillis()
)
)
priceCache[itemId] = priced
return priced
}
}
Features for the pricing model
@dataclass
class PricingFeatures:
# Demand signals
views_last_1h: int
add_to_cart_rate_1h: float
active_sessions_on_item: int
# Supply
stock_level: int
days_until_expiry: Optional[int] # for perishables
# User segment
user_ltv_bucket: int # 0-4 (low to high value)
user_price_sensitivity: float # elasticity from history
# Time context
hour_of_day: int
day_of_week: int
is_payday_week: bool # 1-7 and 25-31 of month
# Competitive
competitor_price_delta: Optional[float] # % difference with competitor
user_price_sensitivity is an important feature often overlooked. Compute it from history: how often does the user buy after a price drop vs. at full price? High-elasticity users get personalized discounts; price-insensitive users don't.
A/B testing pricing strategies
Testing pricing strategies is harder than UI changes. Cannibalization bias: a user in the control group sees one price, in the test group another, but they compete for the same inventory. The right approach is geo-segmentation or time-based segmentation (holdout weeks).
// iOS: display price with badge if dynamic
struct ProductPriceView: View {
let pricedItem: PricedItem
var body: some View {
HStack(spacing: 6) {
if let original = pricedItem.originalPrice, original > pricedItem.currentPrice {
Text(original.formatted(.currency(code: "USD")))
.strikethrough()
.foregroundColor(.secondary)
.font(.subheadline)
}
Text(pricedItem.currentPrice.formatted(.currency(code: "USD")))
.font(.headline)
.foregroundColor(pricedItem.isDiscounted ? .red : .primary)
if pricedItem.priceExpiresIn < 600 { // <10 minutes
Text("⏱ \(pricedItem.priceExpiresIn / 60) min")
.font(.caption)
.foregroundColor(.orange)
}
}
}
}
A timer until price expiry creates urgency without manipulation—users see a real constraint, not a fake countdown.
Process
Audit data: sales history, current demand signals, competitor price availability.
Build a baseline rule-based strategy and collect data for the ML model.
Train and validate the model on offline data.
Develop pricing API and client-side session cache.
Online testing with geo-segmentation and revenue + conversion monitoring.
Timeline estimates
Rule-based dynamic pricing with API—1 week. ML model with feature engineering and offline validation—3–4 weeks. Full system with online A/B testing and monitoring—6–8 weeks.







