Architecture decisions · Performance and scale

The database or API is the bottleneck

A page or an API call is slow, slower under load, and the first proposal is more servers or the cause everyone already suspects.

01

How it is diagnosed

A baseline first; then the tool that shows each cause: the database's statement statistics and query plans, a CPU profile and the server's counters, under the load users really produce.

02

The options, side by side

Switch on a situation and see what each option does with it.

A

Fix the most likely cause first

The cause is a missing indexFound only if it was the suspected cause.

Connections are held during a slow external callRarely suspected: no query is slow.

A code review flags an obvious defectIt is fixed first, with no measured gain while requests are fast.

When it fits
The cause is obvious and the system is small.
Trade-offs
If causes stack, the gain cannot be credited and the real cause stays.

B

Add hardware

The cause is a missing indexMore cores scan faster; the full scan stays, and grows with the data.

Connections are held during a slow external callMore servers queue on the same connection pool.

A code review flags an obvious defectNothing changes.

When it fits
A deadline cannot wait for diagnosis.
Trade-offs
It hides the cause until the data grows again, and costs every month.

C

Measure first, then change one thing at a time

The cause is a missing indexThe statistics point at one statement; in the lab, three indexes took the page from 1,053 to 42 ms.

Connections are held during a slow external callThe database's waits show sessions idle in a transaction; in the lab, moving the call out of it took 229 to 45.7 ms.

A code review flags an obvious defectReintroduced in isolation, it made no difference; a regular expression per row that nobody suspected cost 7x.

When it fits
The cause is unclear, or the change has to be justified afterwards.
Trade-offs
Slower to the first gain, and it needs a reproducible case.

03

What decides between the options

Which stage holds the time, and whether the cost is in a query, in the code, or in how long a connection or a row lock is held.

What decidesA Fix the most likely cause firstB Add hardwareC Measure first, then change one thing at a time
Knowing what mattered What is not measured cannot safely be kept or undone. limited Only if the suspected cause was the real one. limited No. suits it Each cause measured alone.
Detecting a regression A later change can bring the cause back. limited No. limited No. suits it The same day, with the same command.
Time to the first gain Sometimes the business needs relief this week. suits it Short. suits it The shortest. needs work Longer: the measurement comes first.
Knowing what mattered A B C

What is not measured cannot safely be kept or undone.

  • A · Fix the most likely cause first limited Only if the suspected cause was the real one.
  • B · Add hardware limited No.
  • C · Measure first, then change one thing at a time suits it Each cause measured alone.
Detecting a regression A B C

A later change can bring the cause back.

  • A · Fix the most likely cause first limited No.
  • B · Add hardware limited No.
  • C · Measure first, then change one thing at a time suits it The same day, with the same command.
Time to the first gain A B C

Sometimes the business needs relief this week.

  • A · Fix the most likely cause first suits it Short.
  • B · Add hardware suits it The shortest.
  • C · Measure first, then change one thing at a time needs work Longer: the measurement comes first.

04

What the work looks like

The step of the offer where a case like this usually starts:

03

Architecture assessment

Findings, risks, options and next steps, in writing. A good starting point when the scope is not yet clear.

See the service: Performance and scale →

05

Is this your case?

Send it with this problem already selected; the next page asks which options you considered and a little context. No verdict on your system: that only comes once I understand it.

Send this case →

Or write to me directly at contacto@danielcolaco.pt.