Sub-15ms DynamoDB Scatter-Gather Parallel Queries & Write Sharding in Go

A single Amazon DynamoDB physical partition supports up to 1,000 Write Capacity Units (WCU) and 3,000 Read Capacity Units (RCU). When a flash sale, viral campaign, or high-frequency telemetry stream hammers a single partition key (such as PK = FLASH_SALE#2026_11_02), DynamoDB throttles requests with ProvisionedThroughputExceededException even if your table has plenty of global capacity. As a cloud engineer and backend engineer, I eliminate hot-partition throttling using deterministic write sharding and concurrent scatter-gather queries in Go.

1. Write Sharding Across N Virtual Partitions & Concurrent Scatter-Gather Reads

By appending a shard suffix 0..N-1 to the partition key on write (`PK = EVENT#991#SHARD#3`), write throughput scales linearly to N * 1,000 WCU. To read the aggregated leaderboard or recent activity in under 15ms, our Go service fans out N parallel Query calls using errgroup.Group and merges the sorted results in memory:

// store/sharded_query.go
package store

import (
	"context"
	"fmt"
	"sync"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/service/dynamodb"
	"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
	"golang.org/x/sync/errgroup"
)

const ShardCount = 8

func QueryShardedEventEntries(ctx context.Context, client *dynamodb.Client, tableName, eventID string) ([]map[string]types.AttributeValue, error) {
	var (
		mu      sync.Mutex
		results []map[string]types.AttributeValue
	)
	g, gCtx := errgroup.WithContext(ctx)

	for shard := 0; shard < ShardCount; shard++ {
		shardID := shard
		g.Go(func() error {
			pk := fmt.Sprintf("EVENT#%s#SHARD#%d", eventID, shardID)
			out, err := client.Query(gCtx, &dynamodb.QueryInput{
				TableName:              aws.String(tableName),
				KeyConditionExpression: aws.String("PK = :pk"),
				ExpressionAttributeValues: map[string]types.AttributeValue{
					":pk": &types.AttributeValueMemberS{Value: pk},
				},
				Limit:            aws.Int32(25),
				ScanIndexForward: aws.Bool(false),
			})
			if err != nil {
				return err
			}
			mu.Lock()
			results = append(results, out.Items...)
			mu.Unlock()
			return nil
		})
	}

	if err := g.Wait(); err != nil {
		return nil, err
	}
	return results, nil
}

2. Tuning HTTP/2 Connection Pools for AWS SDK Go v2

Default Go HTTP transport settings (`MaxIdleConnsPerHost: 2`) cause connection churn when firing 8–16 concurrent DynamoDB queries per request. Always configure a custom `http.Transport` with `MaxIdleConnsPerHost: 128` on your DynamoDB client.

3. Related AWS & High-Concurrency Backend Resources


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 15+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs