The Problem
Tripvento's city-matrix endpoint returns every hotel in a city scored against 14 traveler personas. At 33 cities it felt fast. At 212 cities, with 24,000+ hotels, cold responses were creeping toward 700ms and the payload for a single city had quietly reached 1.8MB.
Nothing was broken. No alerts were firing. But I knew what that feeling meant. I was about to hit a wall.
Before touching a single line of code, I opened a Django shell and started measuring.
Profile First. Fix Second.
The biggest mistake I see in performance debugging is jumping straight to solutions. Add an index. Throw in a cache. Upgrade the droplet. All of these can mask the real problem while adding complexity.
I isolated each layer independently:
import time
from hotels.models import StagingHotel, StagingHotelIntent
from hotels.serializers import HotelIntentMatrixSerializer
from django.db.models import Prefetch
# layer 1 raw query
start = time.time()
qs = list(StagingHotel.
Discussion
Be the first to comment
Add your perspective to get the discussion started.