INFRASTRUCTURE

Same features, flat response times.

As BCE's client base and file volume grew, two modules started showing their age: the virtual folder system and client management. Pages that used to load instantly were starting to lag.

PythonSQLDjangoPostgreSQL
Query Profiler — Client List View
Client list view — response time
BEFORE
340ms · 48 queries
AFTER
60ms · 3 queries
Large folder download — peak memory
BEFORE
~600MB buffered
AFTER
~40MB streamed
The Breakdown

The Problem

Profiling turned up the usual suspects, but at scale: N+1 queries firing on every list view, permission checks running one row at a time, and large folder downloads loading an entire ZIP into memory before sending anything to the browser. None of it was broken — it just hadn't been built for the data volume it was now handling.

What I Built

Query optimization across both modules using select_related and prefetch_related to collapse N+1 patterns into single queries. Large folder downloads were rewritten to stream the ZIP directly to the client instead of assembling it fully in memory first. Permission checks were batched into bulk lookups, and targeted database indexes were added on the columns those views actually filter and sort by.

Process

How it works.

01

Profile

Instrument the slow views to see where time was actually going, rather than guessing.

02

Collapse queries

Apply select_related and prefetch_related wherever N+1 patterns showed up, turning dozens of queries into one.

03

Stream, don't buffer

Rewrite large folder downloads to stream the ZIP as it's built instead of assembling it fully in memory first.

04

Index what's queried

Add indexes only on the columns the slow queries were actually filtering and sorting by.

Outcome
2
MODULES
OPTIMIZED
0
FULL-ARCHIVE
MEMORY LOADS
FLAT
RESPONSE TIMES
AS DATA GREW
Why it matters

None of this shipped as a visible feature — nobody sees a changelog entry for "pages load faster." But it's the difference between BCE staying usable as the client base grows and slowly becoming the thing everyone quietly complains about.