Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › caching

Database Scaling: Choose Indexes, Replicas, Caches, or Shards by Bottleneck

By Freedom251 Team · · 11 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Database scaling is not a checklist in which every system graduates from indexes to replicas to sharding. It is a diagnosis-and-measurement exercise: find the saturated resource or expensive operation, apply the smallest change that addresses it, and measure representative traffic again. An index can reduce lookup work; replication can add read capacity and failover options; a cache can absorb repeated reads; sharding can distribute a dataset that no longer fits or perform on one node. Each also adds a different class of cost and failure.

The practical starting point is your database engine’s query plans and workload metrics. PostgreSQL’s version 16 documentation uses EXPLAIN and planner statistics to show where a query spends work. Replication, caching, and sharding should follow evidence about availability, read patterns, consistency requirements, memory, storage, and throughput—not a universal size threshold.

As an Amazon Associate I earn from qualifying purchases.

Scaling starts with a measured bottleneck

“The database is slow” is an outcome, not a diagnosis. A CPU-bound query, lock contention, exhausted connection pool, disk latency, insufficient memory, replication lag, and an application sending the same request thousands of times can all produce similar symptoms. The remedy depends on which resource is actually limiting the workload.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Establish a baseline

Capture a representative period that includes normal traffic and the peak you care about. Record latency percentiles rather than only an average, throughput, error rate, CPU, memory pressure, storage latency and queue depth, active connections, lock waits, transaction rate, and, where applicable, replica lag and cache hit/miss rates. Keep the query mix: a synthetic test containing only one fast lookup can hide a slow report or a write-heavy endpoint.

#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter | 4Pack Type C Female to A Male Cable Converter for Apple Duo 17 16 15 14 Plus,iWatch Watch 12 11 10,iPad 9 8 Air,Airpods 5 4
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Inspect the operation doing the work

For a slow PostgreSQL statement, begin with EXPLAIN and compare the planner’s estimates with observed behavior. Look for sequential scans over a large relation, expensive sorts, repeated nested-loop work, joins that process far more rows than expected, or estimates that differ greatly from reality. Planner statistics help the optimizer choose a path, but a plan is not a benchmark: measure the statement under a safe, representative workload before and after a change.

Separate read, write, and availability problems

  • A read query that examines too many rows may need a better access path, a query rewrite, or precomputed data.
  • Writes slowed by index maintenance, locks, or storage limits need a different response from reads slowed by repeated requests.
  • A requirement to survive a server failure is an availability problem; adding an index cannot solve it.
  • A single node that has reached its storage or throughput ceiling may eventually require partitioning or sharding, but distributing data before the access pattern is understood creates avoidable complexity.

PostgreSQL’s documentation describes synchronization as the fundamental difficulty for servers working together. That observation applies to every design in which multiple components must agree about changing data: scaling out changes the coordination problem as well as the capacity.

Indexes: make a suitable access path cheaper

An index is a separate data structure that helps the engine find rows without examining every row in a table, or helps it produce rows in a useful order. Its value is query-dependent. A predicate, join key, or ordering operation that is selective and frequently executed is a candidate; a column with little selectivity, a query that returns most of the table, or an expression the index does not cover may see little benefit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Match the index to real queries

Start from statements in your workload, not from a list of columns that “might be useful.” Inspect filters, join conditions, ordering, and grouping in the actual SQL. Then check the plan to see whether the optimizer can use the proposed access path and whether the resulting row estimates are credible. Different PostgreSQL index types have different strengths, so select one only when its behavior matches the operator and data shape used by the query.

For example, if an endpoint repeatedly looks up a small set of recent orders for one customer, an index aligned with the customer filter and the query’s ordering may reduce work. If a report returns nearly every row, an index may add maintenance cost while leaving the dominant scan and aggregation largely unchanged. A plan that still spends most of its time sorting, joining, or waiting on I/O points to a different bottleneck.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter | USB C Dongle with 90W Max Power Delivery, 3×5Gbps USB A Data Ports, for MacBook, Dell, and More (Charger Not Included)
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Account for the price of every index

  • Storage: the index occupies disk and can increase backup, restore, and cache-footprint requirements.
  • Write work: inserts, updates, and deletes must maintain every affected index, increasing CPU and I/O.
  • Maintenance: indexes require monitoring and, depending on workload and engine behavior, routine maintenance to control bloat and statistics quality.
  • Write-path contention: adding several indexes to a hot table can lengthen transactions even when reads become faster.

Measure both sides. A lower latency for one read is not an overall win if write latency, storage growth, or maintenance windows become unacceptable.

A safer index rollout

  1. Identify the slow or high-volume statement from production telemetry.
  2. Capture its current plan and execution measurements under representative parameters.
  3. Form one hypothesis about the missing access path or inaccurate statistics.
  4. Create the smallest index that tests that hypothesis, using your PostgreSQL version’s operational guidance for building indexes safely.
  5. Re-run the workload, checking read latency, write latency, lock impact, storage consumption, and plan stability.
  6. Keep the index only if the whole workload improves; otherwise remove it and record why the hypothesis failed.

Replication: copies for availability and read distribution

Replication keeps data on more than one server. In PostgreSQL’s primary-and-standby model, the primary accepts writes while standby servers follow its changes. A hot standby can accept read-only queries. This arrangement can provide a failover target and, when the application can tolerate the consistency model, distribute some reads.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Synchronous and asynchronous behavior

Mode Commit behavior What it improves What it costs
Synchronous replication A modifying transaction waits for the configured replica or replicas to confirm the change before commit completes. Stronger guarantees that a promoted standby has acknowledged committed transactions. Network delay and an unavailable or slow replica can directly increase write latency or block commits.
Asynchronous replication The primary can commit before a standby has received and applied the change. Lower write-path impact when the network or standby is slow. Replication lag can produce stale reads, and a promoted standby may be missing the newest transactions.

The right setting depends on the loss and staleness the workload can accept. Synchronous replication across a slow network can materially reduce performance; asynchronous replication reduces that impact but makes lag and potential data loss during promotion part of the design.

Do not treat a replica as a transparent primary

Routing a read to a standby immediately after a write can return older data under asynchronous replication. Applications need an explicit policy: send consistency-sensitive reads to the primary, wait for an appropriate replication point, or accept bounded staleness. A read-only standby also cannot replace the primary’s write capacity. It may relieve read pressure, but all changes still originate at the write leader and must be propagated.

Plan failover, not just copying

Failover requires a promotion procedure, connection routing, monitoring, and a decision about what happens to clients that still point at the old primary. Test the procedure, including a standby that is behind, a network partition, and a primary that returns after promotion. Replication health metrics should include lag, apply delay, disconnected standbys, and the age of the newest transaction known to be durable on each candidate.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter | 85W Max PD, 2 USB 3.0 & 1 USBC Data Ports, SD/TF Card Reader, for Laptops/Mac and Other Type C Devices (Charger Not Included)
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Caching: remove repeated reads from the database path

An external cache stores selected objects or query results outside the database server. Microsoft Learn’s Azure PostgreSQL guidance describes the strongest fit as read-heavy traffic, repeated data, expensive stable queries, or short-lived spikes. The database remains the source of truth; the cache is an optimization layer with its own availability and correctness behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When a cache helps—and when it does not

  • Good candidates are values requested repeatedly, changed relatively infrequently, and acceptable to serve within a stated freshness window.
  • Write-heavy workloads gain less when each request changes data and invalidates the entry.
  • Queries that are already fast and rarely repeated may not justify another network hop and service to operate.
  • Data that must be transactionally consistent on every read needs a carefully defined read path; a casually added cache can violate that requirement.

Do not promise a universal speedup. Benefit depends on the hit rate, serialization cost, network distance, object size, miss behavior, and the database work avoided.

Choose an explicit cache pattern

Pattern Request flow Decision you must document
Cache-aside Check the cache; on a miss, read PostgreSQL, return the value, and populate the cache. TTL, invalidation rules, stampede protection, and what happens when the cache is unavailable.
Reference-data prefetch Load stable lookup data ahead of requests and refresh it when the source changes. Refresh trigger, startup behavior, and an upper bound on staleness.
Write-through Coordinate a write to the database with an update to the cache. Ordering, retry behavior, and how to reconcile a partial failure.
Event-driven invalidation Use a data-change event to invalidate or refresh affected entries. Delivery guarantees, duplicate events, ordering, and recovery after an event outage.

Design for misses and stale data

Set a finite TTL even when events normally invalidate entries. Handle a cache outage by falling back to the database with load protection rather than allowing every client to retry aggressively. Prevent a thundering herd by coalescing concurrent misses or applying bounded backoff. Define which fields may be stale and for how long; “cached” is not a correctness policy by itself.

Sharding: distribute data past one node’s ceiling

Sharding divides a dataset among servers so that storage and work are spread across them. It becomes relevant when one node’s memory, disk, or throughput limit is the constraint and vertical improvements no longer provide enough headroom. The application or a cluster layer must map each key to the shard that owns it.

Key placement determines the system’s shape

A good shard key keeps related, frequent operations together while distributing load. A poor key creates a hot shard, forces cross-shard joins, or makes a single tenant consume one node’s capacity. Queries that need records from several shards require fan-out and merge logic, adding latency and failure points. Transactions spanning shards are more complex than transactions confined to one owner.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray | Data transfer & Fast charging for MacBook, iPhone 17/16/15, iPad, Samsung Galaxy, Apple Watch
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Redis Cluster’s concrete mapping

Redis documentation describes Redis Cluster as using 16,384 hash slots as an intermediate mapping layer between keys and shards. The slot count is a Redis implementation detail, not a general database-scaling constant. Adding or removing shards can move slots and keys, so resharding consumes network, CPU, and operational attention while the system remains available. Capacity planning must include shard memory limits, replica overhead, placement, and the temporary cost of moving data.

Know when to postpone sharding

If the workload is primarily a few slow queries, a missing index or query redesign is less disruptive. If repeated reads dominate, a cache may defer pressure without repartitioning the dataset. Sharding should be a response to a demonstrated single-node ceiling, not a default destination for every growing application.

These techniques solve different bottlenecks

Technique Primary problem addressed Main tradeoff
Indexing An access path that scans or sorts too much data. Additional storage plus write and maintenance work; usefulness depends on plans and workload.
Replication Availability, failover, and some read distribution. Synchronization delay, consistency choices, and performance effects on writes.
Caching Repeated reads and latency-sensitive access to stable data. Staleness, invalidation, misses, and another service and application path.
Sharding A single node’s storage or throughput limit. Key distribution, cross-shard work, resharding, and operational complexity.

A cache is not a write-scaling mechanism. A read replica is not automatically a consistent substitute for the primary. An index cannot repair every expensive query. Combining layers can be valid—for example, indexed queries on a primary with asynchronous read replicas and a cache—but each layer needs its own correctness and failure policy.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A practical sequence for scaling a service

  1. State the target: define acceptable latency percentiles, throughput, data-loss tolerance, freshness, and availability.
  2. Measure the baseline: capture resource metrics, query-level timings, plans, connection behavior, and workload mix.
  3. Fix the narrowest bottleneck: improve a query or add one evidence-backed index before introducing distributed components.
  4. Re-measure under peak-like traffic: verify that the change helps the intended metric without moving pressure to writes, storage, or locks.
  5. Add replication for a stated availability or read-routing requirement: choose synchronous or asynchronous behavior based on consistency and latency needs.
  6. Add caching for repeated, freshness-tolerant reads: document TTL, invalidation, miss handling, and fallback load limits.
  7. Shard only after proving a single-node ceiling: choose a shard key, test cross-shard operations, and rehearse resharding.
  8. Automate rollback and observe the new failure modes: every additional layer needs alerts, runbooks, and a tested recovery path.

Common failure modes and corrective actions

“We added indexes, but writes became slow”

Measure index size, write latency, and the statements that changed. Remove redundant or low-value indexes, keep only those supported by production plans, and schedule maintenance with the table’s write pattern in mind.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“The replica serves old data”

Inspect replication lag and route read-after-write operations to the primary or a consistency-aware path. If the lag is unacceptable, investigate network, standby apply capacity, and synchronous settings rather than hiding the symptom in application retries.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display | 85W Max PD, 1 Powered USB-C 5Gbps & 2 Powered USB-A 3.0 5Gbps Data Ports, for MacBook Pro, MacBook Air, Dell and More (Black)
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

“The cache made incidents worse”

Check whether an outage caused a cache stampede, whether TTLs expired together, or whether invalidation failed. Add request coalescing, staggered expiration, bounded database fallback, and an explicit stale-data policy.

“One shard is hot while others are idle”

Analyze key frequency and tenant distribution. A new key strategy or deliberate splitting of hot keys may be required; simply adding a node does not move load unless keys or slots are redistributed.

Worked choices by workload

Many lookups, few writes, one large table

Begin with query plans and a targeted index. If the same stable objects are requested repeatedly, add cache-aside with a defined TTL. Replication may provide failover, but it does not replace the access-path work.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read-heavy application with strict recovery requirements

Use a primary and standby design, decide whether synchronous confirmation is worth the write latency, and route only consistency-tolerant reads to replicas. Add caching only for data whose freshness contract is explicit.

High-volume key-value workload beyond one node’s memory

Sharding can distribute keys, but select and test the key mapping before production. For Redis Cluster, account for its 16,384 hash slots, replica memory, hot keys, and the operational work of moving slots during resharding.

Costs that appear on the operations budget

Scaling is not only a server bill. Indexes increase storage and backup volume. Replicas consume compute, storage, monitoring, and network bandwidth, and require promotion drills. Caches add an independently operated service, serialization and invalidation code, and a fallback path. Shards multiply deployment units and complicate migrations, incident response, and data repair. Include engineering time for observability, testing, and recovery in the decision.

PostgreSQL documentation cited here is for version 16; check the documentation for the version you deploy because planner behavior and capabilities can change. Redis behavior such as hash-slot mapping is product- and version-specific. Cloud service features and availability can also change, so validate them against the service documentation and your region before committing to an architecture.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Further reading for database internals

Readers who want a deeper treatment can consult Database Internals by Alex Petrov. O’Reilly describes it as an intermediate-to-advanced book covering B-tree storage, caching, replication and consistency, and distributed systems; its ISBN is 9781492040330. It is a reference for understanding the mechanisms, not a requirement for choosing a scaling change.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

cachingdatabase replicationDatabase ScalingindexingPostgreSQLquery performanceRedisSharding

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.