Post

Business Shortcuts Are the Most Powerful Performance Optimization

Business Shortcuts Are the Most Powerful Performance Optimization

Introduction

When a page starts slowing down because the database reached millions of records, most developers immediately think about technical optimizations.

And honestly they are usually correct.

You should absolutely think about:

  • Database indexes
  • Fixing N+1 queries
  • Reducing unnecessary selected columns
  • Pagination
  • Query optimization
  • Better caching
  • Background processing
  • Better serialization logic
  • Optimized calculations
  • Reducing database round trips

These things matter a lot.

But after years working on production systems, I learned something much more powerful:

The biggest performance gains sometimes come from understanding the business itself.

Not the database.

Not Django.

Not PostgreSQL.

The business.


The Normal Technical Optimization Path

When performance becomes slow, developers usually start with technical fixes:

  • Adding indexes,
  • Fixing N+1 queries with select_related/prefetch_related,
  • Using only() or values() to reduce data transfer (read more on only() and values()),
  • Caching expensive results.

These matter. But after the technical cleanup, ask a more important question:

Why are we loading all this data in the first place?

This single question often outperforms complicated optimizations.

Business Logic Optimization

Imagine a page showing transactions from the entire year.

1
transactions = Transaction.objects.all()

The table now contains:

  • 1 year of data
  • Millions of records
  • Heavy filtering
  • Heavy aggregation
  • Slow exports
  • Expensive counting

Then someone asks:

Does the user really need all one year?

And suddenly the business answer becomes:

Actually users usually only check the latest 90 days.

Now the query becomes:

1
2
3
4
5
6
7
8
from datetime import timedelta
from django.utils import timezone

last_90_days = timezone.now() - timedelta(days=90)

transactions = Transaction.objects.filter(
    created_at__gte=last_90_days
)

Why This Is So Powerful

Reducing the timeframe from 360 days to 90 days means processing roughly 25% of the original data — a ~75% reduction.

This typically creates massive performance improvements, and the code change was minimal.

Hidden Business Shortcuts

This is where senior developers become extremely valuable.

Not because they know more syntax.

But because they understand the flow of the business.

Over time, experienced developers start discovering shortcuts like:

  • Returning early before expensive calculations
  • Skipping unnecessary validations in some states
  • Avoiding entire workflows for archived objects
  • Reducing calculations for completed entities
  • Delaying expensive operations to background jobs
  • Using pre-aggregated business data
  • Avoiding recalculating immutable results
  • Running some operations only for active customers

These shortcuts are usually invisible to newer developers.

Because they require business understanding.

Real Production Example

Imagine an export system.

The original flow:

  • Load all orders
  • Calculate discounts
  • Calculate shipment prices
  • Generate statistics
  • Serialize everything
  • Export file

But after understanding the business flow, you discover:

  • Completed orders never change
  • Old shipment prices are already finalized
  • Historical discounts are immutable

Now you can:

  • Skip recalculating old discounts
  • Skip shipment recalculation
  • Read precomputed values directly
  • Export archived data differently

Suddenly a very slow export becomes much faster.

Not because of a magical database trick.

Because the business allowed it.

Early Return Optimization

One of the simplest and strongest patterns.

Unsafe expensive flow:

1
2
3
4
5
6
7
def calculate_invoice(order):
    total = expensive_calculation(order)

    if order.is_cancelled:
        return 0

    return total

Recommended:

1
2
3
4
5
def calculate_invoice(order):
    if order.is_cancelled:
        return 0

    return expensive_calculation(order)

Very small change.

Huge impact when executed thousands of times.

Technical Optimization Still Matters

This article is not against technical optimization. You still need proper indexing, query optimization, caching, and monitoring.

Without technical foundations, business shortcuts alone are not enough.

But many developers stop at technical optimization only. The real power appears when you combine technical understanding with business understanding.

Why Experienced Developers Become Very Valuable

Experienced developers know which business rules can be skipped, which data users actually need, and which workflows are rarely used. This knowledge is usually undocumented losing it can hurt performance significantly.

Optimization is not always about code. Sometimes it is about understanding the system deeply enough to avoid unnecessary work entirely.

Understanding the domain → Better optimization opportunities

Best Practices

1. Start Technical First

  • Missing indexes
  • N+1 queries
  • Bad joins
  • Missing pagination
  • Heavy serialization
  • Large payloads

2. Then Ask Business Questions

  • Does the user need all this data?
  • Can we reduce the timeframe or skip old records?
  • Can we use summaries or avoid recalculation?
  • Can we defer this operation or stop early?

These questions often unlock the biggest wins.

3. Measure Before and After

Never assume optimization helped. Measure query time, memory usage, and API latency. Optimization without measurement becomes guessing.

Conclusion

Most developers think performance optimization is mainly technical: indexes, caching, better queries, better hardware. These matter.

But some of the biggest gains come from something simpler: understanding the business deeply enough to avoid unnecessary work.

The strongest optimization is sometimes not making the calculation at all. Or not loading the data in the first place.

Performance engineering is not only about code. It is about understanding the real purpose behind the code.

This post is licensed under CC BY 4.0 by the author.