> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Dynamic Sharding

> The process of dynamically scaling to more shards in Quai Network.

## Automatic Network Expansion

Imagine a highway system that automatically builds new lanes when traffic gets heavy. That's essentially what Quai Network does with dynamic sharding - it automatically adds processing capacity when demand increases.

**What is Dynamic Sharding?**
The protocol automatically creates new execution shards (processing channels) when the network becomes congested, expanding capacity without human intervention or network upgrades.

**How It Works:**

1. **Network monitors demand**: Protocol tracks congestion indicators in real-time
2. **Automatic expansion**: When thresholds are met, new region and zone chains are created
3. **Seamless integration**: New chains immediately join the existing consensus system
4. **Balanced growth**: All regions gain additional zones to maintain network harmony

**The Key Advantage:**
Unlike other blockchain networks that require hard forks or compromise security when scaling, Quai adds capacity automatically while maintaining full decentralization and security.

<Frame>
  <img src="https://mintcdn.com/dominantstrategies/BvvhftC0HW11EtQX/images/DynamicSharding.jpg?fit=max&auto=format&n=BvvhftC0HW11EtQX&q=85&s=ce1ff810d5fccb653c0bf02b811088b6" width="1500" height="643" data-path="images/DynamicSharding.jpg" />
</Frame>

## How the Network Knows When to Expand

The protocol monitors two key congestion indicators to determine when new capacity is needed:

### 1. Uncle Block Rate

**What are Uncle Blocks?**
Think of uncle blocks as "traffic jams" in mining. When multiple miners find valid blocks simultaneously, only one becomes part of the main chain - the others become "uncles."

**Why This Matters:**

* **High uncle rate** = Network congestion (too many miners competing for limited space)
* **Reduced efficiency** = Wasted mining energy and slower transaction finality
* **Clear signal** = Time to add more capacity

**How Quai Responds:**
When uncle blocks consistently exceed a threshold ratio, the protocol automatically:

1. Creates new region and zone chains
2. Integrates them into the global consensus
3. Distributes mining power across more chains
4. Reduces congestion and restores efficiency

**Result**: High hash efficiency maintained, fast finality preserved

### 2. Gas Limit Utilization

**What is Gas Limit?**
Each block has a maximum computational capacity (gas limit). When blocks consistently hit this limit, it means demand exceeds supply.

**The Fee Problem in Other Networks:**

* **Ethereum example**: When blocks are full, fees can reach \$50+ per transaction
* **Bidding wars**: Users compete by paying higher fees for limited block space
* **User experience**: Transactions become expensive and unpredictable

**Quai's Solution:**
When blocks consistently reach their gas limit, the protocol automatically adds new execution shards, ensuring:

* **Fees stay under \$0.01**: Increased capacity eliminates fee competition
* **No bidding wars**: Always enough block space to meet demand
* **Predictable costs**: Users know transaction fees will remain affordable

**Result**: Unlimited scalability without compromising affordability

## The Only Tradeoff: Settlement Time

**How Network Expansion Works:**

* **3×3 start**: 3 regions, 3 zones each = 9 total zones
* **First expansion**: 4×4 layout = 16 total zones
* **Growth pattern**: 5×5, 6×6, 7×7... unlimited expansion

**What's the Tradeoff?**
The only cost of adding capacity is increased **time to global settlement** - but this doesn't affect transaction safety or usability.

## Settlement vs Finality: Why This Matters

**Critical Distinction:**

* **Finality**: When your transaction is permanent and safe (seconds in Quai)
* **Settlement**: When funds can be spent cross-chain (minutes to hours)

**Real-World Impact:**

* ✅ **Your transaction is safe** immediately after finality
* ✅ **Recipients can trust payment** without waiting for settlement
* ⏳ **Cross-chain spending** requires settlement completion

**Example Timeline:**

1. **10 seconds**: Transaction finalized (safe and permanent)
2. **3,300 seconds**: Global settlement (can spend funds in other regions)

**Why This Design Works:**
Most transactions happen within the same region where settlement is fast. Cross-chain operations are less frequent and users can plan accordingly.

## Settlement Time Calculation

**The Formula:**
Average time to Global (prime) settlement can be measured by the following equation, where:

* **TSₚ** = Average time to Global (prime) settlement (in seconds)
* **nz** = Number of zones per region
* **nr** = Number of regions in the system
* **tz** = Zone block time (in seconds) = 5

$$
TS_{p} = n_{z}^2 * n_{r}^2 * t_{z}
$$

**What This Means:**

* Settlement time increases with the square of both regions and zones per region
* **5 seconds**: Zone block time (where most transactions occur)
* **Total time**: Scales predictably with network size

<br />

<br />

| Number of Regions | Number of Zones per Region | Total Zones | Time to Global Settlement† |
| ----------------- | -------------------------- | ----------- | -------------------------- |
| 3                 | 3                          | 9           | 405s                       |
| 4                 | 4                          | 16          | 1,280s                     |
| 5                 | 5                          | 25          | 3,125s                     |
| 6                 | 6                          | 36          | 6,480s                     |
| 7                 | 7                          | 49          | 12,005s                    |
| 8                 | 8                          | 64          | 20,480s                    |

**Important Notes:**

* Settlement times are **averages** - actual times vary due to the random nature of mining
* **\~50% of transactions** settle faster than the average time
* **All transactions** are final and secure well before settlement completes

**Understanding the Distribution:**
The diagram below shows how cross-chain transaction times are distributed. While the average global settlement is 3,300 seconds, half of transactions complete faster than this.

<Frame>
  <img src="https://mintcdn.com/dominantstrategies/BvvhftC0HW11EtQX/images/Cross-PrimeTransactions.png?fit=max&auto=format&n=BvvhftC0HW11EtQX&q=85&s=eb92187ab37e48ce73e4f4e78624a1c6" width="1280" height="866" data-path="images/Cross-PrimeTransactions.png" />
</Frame>
