Operations

Performance & Resource Use

Foundational

Performance is a feature, and resources are limited. The goal is not to make everything as fast as possible. It is to be fast enough where it matters, efficient with the resources we pay for, and free of the leaks and unbounded operations that turn a busy day into an outage. Measure before you optimise, and design so load cannot run away.

Most performance problems are not unusual. They are an N+1 query, an unbounded result set, a missing index, a synchronous call that should be async, or a resource that is allocated and never released. The approach is to treat performance as a design choice (especially on hot paths and data access), to measure rather than guess, and to put limits on everything that grows with input or load.

Optimising too early wastes effort and harms clarity. Ignoring performance until production wastes money and causes outages. The balance is judgement: write clear code, know the cost of your data access and external calls, put limits on anything unbounded, and profile with real data when something is actually slow.

Be efficient by design

Measure, and protect against runaway load

N+1 and unbounded var customers = conn.Query("SELECT * FROM Customers WHERE TenantId=@t", p);
foreach (var c in customers)
c.Orders = conn.Query("SELECT * FROM Orders WHERE CustomerId=@id", new{c.Id});

One query per customer (N+1), and the whole customer table loaded with no paging. This is fine in dev with 20 rows. For a tenant with 200,000, it starves threads and exhausts memory.

Bounded, single round-trip var page = conn.Query(@"SELECT Id, Name FROM Customers
WHERE TenantId=@t ORDER BY Id OFFSET @skip ROWS FETCH NEXT @take ROWS ONLY", p);
// orders fetched in one set-based query keyed by the page's customer ids

Results are paged, columns are explicit, and related data is fetched in a single set-based query. The cost stays flat as the tenant grows.

Self-review checklist

Why it matters: Performance problems usually arrive as outages, not as gradual slowdowns. An unbounded query or a leak that was invisible in testing brings the service down the day a tenant grows or traffic spikes. Designing for efficiency, putting limits on load, and measuring before optimising keeps the system fast where it matters and standing when it is busy.