Library / Case Studies
Elasticsearch Performance Tuning Practice at eBay
Elasticsearch is an open source search and analytic engine based on Apache Lucene that allows users to store, search, analyze data in near real time. While Elasticsearch is designed for fast queries, the performance depends largely on the scenarios that apply to your application, the volume of data you are…
By eBay engineers · eBay · Added 2026-10-12
All content belongs to eBay engineers / eBay. We only link to it and give credit. Report a problem
Learn this case study
About 37 min left. Your work is saved as you go.
What you are about to study
eBay explains a real system. You should know the basics: caching, queues and replication.
Ideas you will meet
- Distributed Systems
- Consensus, time, failure and the fundamentals of scale-out.
- Databases
- Schemas, indexes, query plans and choosing a store.
- Search
- Inverted indexes, relevance, autocomplete and search engines.
What we already know about this
Our own lessons on these ideas. Read them here before you start, so it makes sense.
Search, Analytics and Geo · 11 minSharding a search index: scatter, gather and mergeHow a search index is split across machines, why queries fan out to every shard, how top-k results are merged, and what goes wrong with deep paging and uneven shards.Read here
Why shard
One machine cannot hold or search a very large index within the latency budget. Sharding splits the index into pieces, each on its own machine, so storage and work are spread out. Replicas copy each shard for availability and extra read capacity.
Before: one big index
100%After: sharded, scatter and gather
100%What changed
- Storage and work are spread over machines
- Each shard returns its own top results to be merged
- The slowest shard decides how fast the query is
Two ways to partition
- Document-partitioned (local index): each shard indexes a subset of the documents and holds a complete inverted index for them. Writes touch one shard. Every query must visit every shard. This is what Elasticsearch and Solr do.
- Term-partitioned (global index): each shard holds the postings for a subset of terms. A query touches only the shards for its terms, but a write touches many shards and long posting lists must be combined across machines. It is rare in practice.
100%Figure SDA-SAG-05-1 · Scatter, gather and merge · © forcsguy.com
Decisions that matter
- Shard size and count. Too many tiny shards waste memory and add fan-out; too few huge shards recover slowly and cannot spread load. Many teams aim for tens of gigabytes per shard. The primary shard count is hard to change later, so plan for growth or use time-based indexes.
- Routing. By default a document goes to a shard by hashing its id, which spreads data evenly. Routing by tenant or user keeps one customer's data together so queries can hit a single shard, at the risk of uneven shards.
- Tail latency. A query is as slow as its slowest shard. Use replicas, timeouts, and hedged requests (send to a second replica if the first is slow).
- Deep pagination. Page N needs the first N x pageSize results from every shard. Use cursors (search-after) instead of large offsets.
- Scoring across shards. Each shard computes statistics such as IDF from its own documents. Even, large shards make the difference small; otherwise gather global statistics first.
- Rebalancing and reindexing. Plan how to add capacity without downtime, usually by indexing into a new index and switching an alias.
100%Figure SDA-SAG-05-2 · Time-based indexes · © forcsguy.com
Keeping the index fresh
Documents usually live in a primary database and are copied to the search index. Use a change stream or an outbox so updates are not lost, accept that search is eventually consistent, and keep a way to rebuild the whole index from the source of truth.
Real-world reading
Related reading
Big Data and Cloud Data Platforms · 11 minHow big data evolved, and the papers behind itFrom single databases to Hadoop, Spark, streaming and lakehouses: a timeline of ideas and the research papers that started each one.Read here
Why a new wave kept appearing
Each generation of data tools answered a limit of the previous one. Understanding the problem behind each wave makes the tools easier to place.
Image: Trower, NASA · Public domain · Source · Wikimedia Commons: Columbia Supercomputer - NASA Advanced Supercomputing FacilityA timeline
100%Figure SDA-BDP-01-1 · A timeline · © forcsguy.com
1. Before: relational databases and data warehouses
Data fit on one big server. SQL and data warehouses served reports. Limits: scaling up got very expensive, and unstructured data (web logs, clicks) did not fit neatly.
2. Web scale (around 2003 to 2006)
Search companies had far more data than any single machine could hold. Google described how it coped, and open-source projects copied the ideas.
- GFS (Google File System): a distributed file system on commodity machines that expects failures.
- MapReduce: a model to process huge datasets in parallel.
- Hadoop (HDFS plus MapReduce) brought both to everyone.
3. NoSQL (about 2006 to 2010)
Web applications needed massive scale and high availability that relational systems struggled to give.
- Bigtable: a sparse, sorted, wide-column store; inspired HBase and Cassandra's data model.
- Dynamo: an always-writable key-value store with consistent hashing and eventual consistency; inspired Cassandra, Riak and DynamoDB.
4. Faster and friendlier processing (2010 onward)
- Dremel: interactive SQL over huge datasets using columnar storage and tree-shaped execution; the idea behind BigQuery and later engines, and the Parquet format.
- Spark (resilient distributed datasets): keeps data in memory between steps, much faster than disk-based MapReduce for iterative work, with friendly APIs.
5. Streaming
Waiting for nightly batches was too slow. Kafka made a durable, replayable log the backbone of event pipelines, and engines such as Flink and the Dataflow model handled continuous computation with proper treatment of event time, windows and late data.
6. The cloud
Cloud providers separated storage (cheap object storage) from compute (elastic clusters or serverless queries). Managed warehouses (BigQuery, Redshift, Snowflake and others) removed cluster management.
7. The lakehouse
Data lakes were cheap but unreliable (no transactions, messy files). Table formats (Delta Lake, Apache Iceberg, Apache Hudi) add ACID transactions, schema evolution and time travel on top of files in object storage, so one copy of data can serve both analytics and machine learning.
100%Figure SDA-BDP-01-2 · Key dates, in order · © forcsguy.com
The classic papers
These are the research papers most often cited. Search the title to find each; most are freely available.
Paper Authors (and year) The idea The Google File System Ghemawat, Gobioff, Leung (2003) Large-file storage across commodity machines, built to tolerate failures MapReduce: Simplified Data Processing on Large Clusters Dean, Ghemawat (2004) A simple map and reduce model with automatic parallelism and fault tolerance Bigtable: A Distributed Storage System for Structured Data Chang and others (2006) A sorted, sparse, multi-dimensional map for structured data at scale Dynamo: Amazon's Highly Available Key-value Store DeCandia and others (2007) Consistent hashing, quorums, vector clocks and eventual consistency Dremel: Interactive Analysis of Web-Scale Datasets Melnik and others (2010) Columnar nested data and tree execution for fast SQL Kafka: a Distributed Messaging System for Log Processing Kreps, Narkhede, Rao (2011) A partitioned, replicated log as the backbone for event data Resilient Distributed Datasets (Spark) Zaharia and others (2012) In-memory, fault-tolerant parallel computing Spanner: Google's Globally-Distributed Database Corbett and others (2012) Strongly consistent, globally distributed SQL using synchronised clocks The Dataflow Model Akidau and others (2015) A unified model for batch and streaming with event time and windows Delta Lake: High-Performance ACID Table Storage over Cloud Object Stores Armbrust and others (2020) Transactional tables on object storage: the lakehouse idea A good companion is Jay Kreps's essay "The Log: What every software engineer should know about real-time data's unifying abstraction" (2013).
What to take away
- Scale-out on cheap machines (GFS, MapReduce) made big data practical.
- Availability versus consistency choices (Dynamo, Bigtable, Spanner) shaped databases.
- Columnar storage (Dremel, Parquet) made analytics fast.
- Logs and streams (Kafka, dataflow) made data continuous.
- Separating storage from compute and open table formats define today's platforms.
Real-world reading
Related reading
- Dremel: Interactive Analysis of Web-Scale Datasets (paper)Melnik et al. · GooglePapers
- Cassandra architecture overviewApache Cassandra · Apache Software FoundationDocumentation
- Fast Order Search using Data Pipeline and Elasticsearch at YelpYelp engineers · YelpCase Studies
- Apache CassandraApache Software Foundation · GitHubGitHub
Show 6 moreShow fewer
- Amazon S3 strong consistencyAmazon Web ServicesDocumentation
- Sherpa: Distributed NoSQL Key-Value Store at YahooYahoo engineers · YahooCase Studies
- Elasticsearch GuideElasticDocumentation
- MapReduce: Simplified Data Processing on Large Clusters (paper)Dean and Ghemawat · GooglePapers
- HBase at SalesforceSalesforce engineers · SalesforceCase Studies
- Columnar DatabasesAmazon Web Services engineers · Amazon Web ServicesCase Studies
Databases Deep Dive · 12 minReplication topologies and multi-region databasesSingle-leader, multi-leader and leaderless replication, how they handle conflicts and lag, and what changes across regions.Read here
Why replicate
Replication keeps copies of data on several machines for three reasons: availability (survive a node failure), read scaling (serve reads from replicas) and latency (put data near users). The hard part is keeping copies consistent while writes continue. (Basics are in the replication and sharding lesson of the foundations course; this lesson compares the topologies.)
Single-leader (primary and replicas)
One node, the leader (primary or master), accepts writes and ships its changes to followers (replicas), which serve reads.
100%Figure SDA-DDV-04-1 · Single-leader replication · © forcsguy.com
- Synchronous replication waits for a follower before acknowledging: safer, slower, and a stalled follower can block writes. Asynchronous is faster but a failover can lose the latest writes. A common compromise: one synchronous follower, others asynchronous.
- Failover must detect failure, choose the most up-to-date replica, redirect clients and ensure the old leader does not come back believing it still leads (split brain).
- Replication lag causes stale reads. Techniques: read-your-writes (route a user's reads to the leader shortly after they write), monotonic reads (keep a user on one replica), and checking replica position.
Multi-leader
Several nodes accept writes (often one per region) and replicate to each other. Benefits: local write latency and continued operation if a region is cut off. Cost: write conflicts.
Conflict handling options:
- Avoid them: route all writes for one record to one leader (for example by user or region).
- Last write wins by timestamp: simple, but silently drops one of two concurrent updates and depends on clocks.
- Merge values (union of sets, counters) using mergeable data types (CRDTs; see the collaborative editing lesson).
- Custom resolution in application code, or ask the user.
Multi-leader also appears in offline-capable apps (each device is a leader) and collaborative editing.
Before: single leader
100%After: multi-leader across regions
100%What changed
- Users in each region write to a nearby database
- Concurrent edits to the same row need conflict handling
- More moving parts to run and monitor
Leaderless (Dynamo-style)
Any replica accepts writes; clients write to several replicas and read from several, using quorums (
W + R > N) to get fresh data (see the key-value store lesson). Background anti-entropy and read repair fix stale copies; versions or vector clocks detect conflicts. It favours availability and is typical of Cassandra and DynamoDB-style stores.100%Figure SDA-DDV-04-2 · Choosing a replication model · © forcsguy.com
Multi-region designs
- Active-passive: one region serves writes; another is a warm standby. Simple; failover loses a little data (the replication lag) and takes minutes.
- Active-active: several regions serve traffic. Requires either partitioning data by home region (each record has one home, cross-region reads are replicas) or true multi-leader conflict handling.
- Global databases use consensus across regions (see the consensus lesson) for strong consistency at the cost of cross-region write latency; some offer tunable consistency per query.
- Latency numbers matter: a cross-ocean round trip is around 100 ms or more, so synchronous cross-region replication adds that to every write.
- Data residency laws may require keeping certain users' data in a region.
Partitioning and replication together
Real systems shard data into partitions and replicate each partition (a leader per partition spreads write load across nodes). Rebalancing, hot partitions and cross-partition transactions are the new problems (see sharding and the consistent-hashing lesson).
Master/slave naming
You will see "master/slave", "primary/replica" and "leader/follower" for the same single-leader idea; most current documentation prefers the last two.
Checklist
- What happens to writes if the leader or a region is lost, and how long?
- How much data can we lose (RPO) and how long can we be down (RTO)?
- How do we handle stale reads from replicas?
- Who resolves conflicts, and how?
- Have we practised failover?
Real-world reading
Related reading
- Active-Active for Multi-Regional ResiliencyNetflix Engineering · NetflixCase Studies
- Designing Data-Intensive ApplicationsMartin Kleppmann · O'ReillyBooks
- Read Consistency with Database Replicas at ShopifyShopify engineers · ShopifyCase Studies
- Uber Schemaless: A Scalable MySQL DatastoreUber Engineering · UberCase Studies
Show 6 moreShow fewer
- Mitigating MySQL Replication Lag and Reducing Read Load at GithubGithub engineers · GithubCase Studies
- Cassandra architecture overviewApache Cassandra · Apache Software FoundationDocumentation
- How Discord Stores Trillions of MessagesBo Ingram · DiscordBlogs
- Spanner: Google's Globally Distributed Database (paper)Corbett et al. · GooglePapers
- Scaling Multitenant Architecture Across Multiple Data Centres at Shopify - Weingarten, Engineering Lead at ShopifyShopifyYouTube
- MIT 6.824: Distributed SystemsRobert Morris · MITCourses
Go deeper on this
A path through videos, articles, other case studies and code on the same ideas as Elasticsearch Performance Tuning Practice at eBay.
Warm upGet the vocabulary first.
Books
Designing Data-Intensive Applications
The standard book on data systems: storage engines, replication, partitioning, transactions, batch and stream processing.
O'ReillyIntermediate
Documentation
Elasticsearch Guide
The reference for indexing, searching and scaling Elasticsearch.
ElasticIntermediate
WatchHow others solve the same problem, on video.
Videos belong to their creators and play from YouTube. More on YouTube (opens in a new tab)
ReadEngineers explain it in their own words.
Papers
Distributed Searching
A real-world engineering write-up from Washington on distributed Searching.
WashingtonIntermediate
Blogs
eBay Tech
Search, marketplace and platform engineering posts from eBay.
eBayIntermediate
See it in another companyThe same ideas, a different system.
Case Studies · Read here
ELK (Elasticsearch, Logstash, Kibana) Stack
As part of the widespread movement towards open source software, the ELK Stack has become the most common log management platform in the world.
LogzIntermediate
Case Studies · Read here
Fast Order Search using Data Pipeline and Elasticsearch at Yelp
Fast Order Search Using Yelp’s Data Pipeline and Elasticsearch Dmitriy Kunitskiy, Software Engineer Jun 1, 2018 Since its inception in 2013, Yelp has grown its transactions platform to tens of...
YelpIntermediate
Read the codeSee how it looks when it is real.
GitHub
CS Video Courses
A list of university computer-science courses with free videos.
GitHubBeginner
GitHub
Engineering Blogs
A huge directory of company engineering blogs to learn from real production systems.
kilimchoiIntermediate
Keep learning
Loading community…