---
title: "Linear programming for fun and profit"
description: "Modal provisions GPU and CPU capacity across multiple clouds with a \"resource solver\" that formulates demand, prices, availability and per-instance limits as a linear program."
url: "https://swe.quest/articles/linear-programming-for-fun-and-profit-77f85e06bfe14840"
canonical: "https://modal.com/blog/resource-solver"
source: "Modal"
published: "2025-05-07"
difficulty: "medium"
kind: "Case study"
reading_minutes: 8
tags: ["capacity-planning","cost-optimization","algorithms","cloud","serverless"]
---

# Linear programming for fun and profit

A post on [Modal](https://swe.quest/sources/modal.md), published 2025-05-07, 8 min read, Case study. Original: [https://modal.com/blog/resource-solver](https://modal.com/blog/resource-solver)

## Summary

Modal provisions GPU and CPU capacity across multiple clouds with a "resource solver" that formulates demand, prices, availability and per-instance limits as a linear program. It solves that program with Google's GLOP simplex solver from OR-Tools and outputs a delta of instances to spin up or down. Cheap preprocessing heuristics, such as pruning instance types, keep solves to fractions of a second rather than minutes, trading a little optimality for predictable scaling latency. Background workers make the actual cloud requests and feed observed capacity-limit failures back into later solves. The approach lets Modal exploit price arbitrage, such as H200s priced below H100s, and saves millions per year.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Capacity planning](https://swe.quest/tags/capacity-planning.md) (Reliability & operations)
- [Cost optimization](https://swe.quest/tags/cost-optimization.md) (Reliability & operations)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)
- [Cloud platforms](https://swe.quest/tags/cloud.md) (Infrastructure)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)

## Prerequisites

- linear programming basics
- cloud instance provisioning ([easy posts on Cloud platforms](https://swe.quest/tags/cloud.md?difficulty=easy))

## Keywords

Modal, GLOP, OR-Tools, simplex algorithm, linear programming, H100, H200

## Related posts

- [A linear programming approach for optimizing features in ML models](https://swe.quest/articles/a-linear-programming-approach-for-optimizing-features-in-ml-models-4a887cc3d592174d.md): Meta Engineering · 2021-07-29 · Medium · 8 min read · Machine learning, Capacity planning, Algorithms, Python, Ads
  Choosing which ML features to admit under limited infrastructure capacity can be framed as an integer linear program that maximizes model gain subject to per-service capacity constraints.
- [How to price serverless GPUs](https://swe.quest/articles/how-to-price-serverless-gpus-860219d00ad9fa69.md): Modal · 2026-07-06 · Easy · 7 min read · Cost optimization, Serverless, Capacity planning, Inference & serving, Hardware
  Whether serverless or reserved GPUs are cheaper comes down to one comparison: the ratio of reserved to serverless cost equals the reservation discount multiplied by the workload's peak-to-average demand ratio, so serverless wins whenever peak-to-average exceeds the discount.
- [How we achieved truly serverless GPUs](https://swe.quest/articles/how-we-achieved-truly-serverless-gpus-d82b0620ff18c95f.md): Modal · 2026-05-12 · Medium · 23 min read · Serverless, Inference & serving, Containers, Storage systems, Capacity planning
  Modal cuts GPU inference replica cold starts from roughly 2,000 seconds to about 50 seconds, a 40x speedup, by attacking each stage of spin-up.
- [Outgrowing Lambda Functions, Not Lambda | Honeycomb](https://swe.quest/articles/outgrowing-lambda-functions-not-lambda-honeycomb-70c5a0734377ce87.md): Honeycomb · 2026-11-25 · Medium · 20 min read · Serverless, Cost optimization, Cloud platforms, Capacity planning, Observability
  Honeycomb moved most of its S3-backed query mapper compute from Lambda Functions to AWS Lambda Managed Instances, eventually cutting query costs 40-56%, though the switchover itself was easy and the savings came from months of tuning.
- [The future of AI needs more flexible GPU capacity](https://swe.quest/articles/the-future-of-ai-needs-more-flexible-gpu-capacity-9253d5fa5c5e3d65.md): Modal · 2024-10-25 · Easy · 7 min read · Capacity planning, Inference & serving, Serverless, Multi-tenancy, Cost optimization
  Inference and many other GPU workloads are highly volatile: Poisson noise, daily and weekly cycles, viral spikes and bursty batch jobs, which pushes fixed-reservation GPU clusters below 50% utilization.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
