Common Backend Performance Optimization Techniques
The article outlines practical backend performance optimization methods such as SQL tuning, eliminating duplicate calls, on‑demand queries, parallel execution, caching, asynchronous processing, JVM parameter tweaks, and horizontal scaling, providing code examples and actionable advice for developers.
SQL Optimization
When an API response exceeds about 200 ms, the primary bottleneck is usually database access; therefore, optimizing slow SQL statements should be the top priority. Poor query habits—unnecessary joins, missing indexes, and selecting unused columns—lead to performance degradation as data volume and concurrency grow.
For large datasets, read‑write separation and sharding become essential.
Eliminate Duplicate Calls
Repeatedly invoking the same database query or RPC service across different methods wastes time. For example:
skuDao.querySkus(productId).stream().map(sku -> {
skuDao.getById(sku.getId());
})Even though the data has already been fetched, the code queries each SKU again, dramatically increasing latency.
On‑Demand Queries
Often a feature only needs a small piece of data, yet developers call heavyweight methods that retrieve excessive information. For instance:
GoodsDetail goods = goodsService.detail(id);
if (goods.getStatus() == GoodsStatusEnum.XXXX) {
// ...
}The detail method pulls many unrelated fields, causing unnecessary slowdown.
Parallel Calls
If an endpoint aggregates several independent RPC or external services, those calls can be executed in parallel to reduce overall latency. Java's CompletableFuture and parallelStream are typical tools, and a dedicated aggregation layer in micro‑services architectures is ideal for this pattern.
Caching
Caching provides the most noticeable performance boost with modest cost, but it must be applied judiciously. For data with low real‑time requirements, simple time‑based expiration suffices. For high‑frequency, real‑time data, a robust cache‑invalidation strategy—such as subscribing to binlog events—is recommended to avoid stale data.
Asynchronous Processing
Non‑critical tasks can be offloaded to background workers. Using thread pools requires careful capacity planning and monitoring. Persistent task storage (e.g., message queues) is essential to prevent loss on service restarts; the article references a dynamic thread‑pool implementation and discusses reliable asynchronous event handling.
JVM Parameter Tuning
JVM tuning is usually a secondary step after SQL optimization. Adjusting GC‑related flags can reduce pause times, but only when the application experiences frequent Full GC pauses.
Scaling Out (Adding Machines)
When a single node reaches its limits, horizontal scaling—adding more application servers, database instances, or cache nodes—becomes the ultimate solution, especially for fast‑growing startups.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.