Scaling Overview for Services

This page provides a comprehensive overview of how each Sourcegraph service scales. In order to support the growth of your instance usage, it is recommended to scale Sourcegraph based on the scaling factors suggested below.

Grafana should be the first stop you make if you plan to expand on one of the scaling factors or when you are experiencing a system performance issue.

Please use the following scaling guideline for services that are using more than 80% of their assigned resources.

Scaling is unnecessary if your resource usage is kept below 80%.

For example, if you plan to add 100% more engaged users, and the resource usage for all services is currently at around 70%, we’d recommend using this documentation as a reference to adjust the resources that list “Number of active users” as one of their scaling factors. You can also use the output from the Resource Estimator as references alternatively.

For assistance when scaling and tuning Sourcegraph, contact us. We're happy to help!

Components Overview

Here is a list of components you can find in a typical Sourcegraph deployment:

Core Components

frontendServes the web application, extensions, and graphQL services. Almost every service has a link back to the frontend, from which it gathers configuration updates.
gitserverMirrors repositories from their code host. All other Sourcegraph services talk to gitserver when they need data from git.
precise-code-intelConverts LSIF upload file into Postgres data. The entire index must be read into memory to be correlated.
repo-updaterTracks the state of repositories. It is responsible for automatically scheduling updates using gitserver and for synchronizing metadata between code hosts and external services.
searcherProvides on-demand un-indexed search for repositories. It fetches archives from gitserver and searches them with regexp.
symbolsIndexes symbols in repositories using Ctags.
syntect-serverAn HTTP server that exposes the Rust Syntect syntax highlighting library for use by other services.
workerRuns a collection of background jobs periodically in response to internal requests and external events. It is currently janitorial and commit based.
zoekt-indexserverIndexes all enabled repositories on Sourcegraph and keeps the indexes up to date. Lives inside the indexed-search pod in a Kubernetes deployment.
zoekt-webserverRuns searches from indexes stored in memory and disk. The indexes are persisted to disk to avoid re-indexing on startup. Lives inside the indexed-search pod in a Kubernetes deployment.

External Services

A list of services that can be externalized. See our docs on Using external services with Sourcegraph for detailed instruction.

codeinsights-dbA PostgreSQL instance for storing code insights data.
codeintel-dbA PostgreSQL instance for storing large-volume code graph data.
jaegerA Jaeger instance for end-to-end distributed tracing.
blobstoreA blobstore instance that serves as a local S3-compatible object storage to hold user uploads for code-intel before they can be processed.
pgsqlA PostgreSQL instance for storing long-term information, such as user information when using Sourcegraph’s built-in authentication provider instead of an external one.
redis-cacheA Redis instance for storing cache data.
redis-storeA Redis instance for storing short-term information such as user sessions.

Monitoring Tools

Sourcegraph provides a number of tools to monitor the health and usage of your deployment. See our Observability docs for more information. You can also learn more about the architecture of Sourcegraph’s monitoring stack in Sourcegraph monitoring architecture

cadvisorA custom cAdvisor instance that exports container monitoring metrics scraped by Prometheus and visualized in Grafana.
grafanaA Grafana instance that displays data from Prometheus and Jaeger. It is shipped with customized dashboards for Sourcegraph services.
prometheusA customized Prometheus instance for collecting high-level and low-cardinality, metrics across services.

Scaling Guideline

This section provides you with a high-level overview of how each Sourcegraph service works with resources, with a list of scaling factors and basic guideline.

cAdvisor

SHELL
A cAdvisor instance. It exports container monitoring metrics scraped by Prometheus and visualized in Grafana.
Resources
OverviewScaling is not necessary as it is designed to be a small footprint service
FactorsIts primary traffic are the requests coming from Prometheus
GuidelineRead the list of known issues that can cause performance issues for cAdvisor

codeinsights-db

SHELL
A PostgreSQL instance for storing code insights data.
Replica
OverviewSingleton
Factors-
GuidelineA Singleton service should not have more than 1 replica
CPU
OverviewExecutes queries
FactorsNumber of active users
Number of repositories
Number of insight series defined
Number of matches per insight series
Compression ratio of insight data
GuidelineKeep the total memory larger than the largest index
Memory
OverviewProcess Indexes
FactorsNumber of active users
Size of all repositories
Number of repositories
Number of insight series defined
Number of matches per insight series
Compression ratio of insight data
GuidelineKeep the total memory larger than the largest index
Storage
OverviewStores code insights data
FactorsNumber of insight series defined
Number of matches per insight series
Compression ratio of insight data
GuidelineDepends entirely on usage and the specific Insights that are being created
TypePersistent Volumes for Kubernetes
Persistent SSD for Docker Compose
The database must be configured properly to consume resources effectively and efficiently for better performance and to avoid regular usage from overwhelming built-in utilities (like autovacuum for example). For example, a Postgres database running out of memory indicates that it is currently misconfigured, and the amount of memory each worker can utilize should be reduced. See our Postgres database configuration guide for more information.

codeintel-db

SHELL
A PostgreSQL instance for storing large-volume code graph data.
Replica
OverviewSingleton
Factors-
GuidelineA Singleton service should not have more than 1 replica
CPU
OverviewExecutes queries
FactorsNumber of active users
Frequency with which the instance runs precise code navigation queries
GuidelineThe default value should work for all deployments. Please refer to the note below for more detail
Memory
OverviewProcess LSIF indexes
FactorsNumber of active users
Frequency with which the instance runs precise code navigation queries
Total size of repositories indexed by Rockskip
GuidelineThe database must be configured properly to consume resources effectively and efficiently. See note below for more detail
The amount of memory each Postgres worker can utilize must be adjusted according to the memory assigned to the database
Increase the memory assigned to each worker proportionally when database queries are slow
Storage
OverviewStores processed upload data
FactorsNumber and size of precise code graph data uploads
Indexer used
GuidelineThe index size and processed size are currently based on indexer used
Requires about 4 times of the total size of repositories indexed by Rockskip
SCIP provides a more stable approximation of index size -> processed
TypePersistent Volumes for Kubernetes
Persistent SSD for Docker Compose
The database must be configured properly to consume resources effectively and efficiently for better performance and to avoid regular usage from overwhelming built-in utilities (like autovacuum for example). For example, a Postgres database running out of memory indicates that it is currently misconfigured, and the amount of memory each worker can utilize should be reduced. See our Postgres database configuration guide for more information.

frontend

SHELL
Serves the Sourcegraph web application, extensions, and graphQL API services.
Replica
OverviewAlmost every service has a link back to the frontend, from which it gathers configuration updates
FactorsNumber of active users
Number of services connected
GuidelineMore engaged users = more replicas
CPU
OverviewAt least one goroutine is dispatched per HTTP request. It is also used to serve Code Insight series
FactorsNumber of active users
Number of user actions performed
Number of insight series defined
GuidelineMore engaged users = more replicas
Memory
OverviewAggregates results before serving them to clients
FactorsNumber of active users
Number of repositories
GuidelineMore engaged users = more Memory
Storage
Overview-
Factors-
Guideline-
TypeNone

gitserver

SHELL
Mirrors repositories from their code host. Other Sourcegraph services communicate with gitserver when they need data from git.
Replica
OverviewHandles requests from other Sourcegraph services for git information
FactorsSize of all repositories
GuidelineWhen the total size of repositories is too large to fit in one replica
CPU
OverviewRuns git commands concurrently
FactorsNumber of active users
Size of all repositories
Size of the largest repository
GuidelineDepends on the amount of git commands need to perform --more git commands = more CPU
Memory
OverviewData associate with the running git commands
FactorsSize of all repositories
Size of the largest repository
GuidelineDepends on the git commands to be executed --the more or larger the git commands = more memory
Storage
OverviewRepositories are cloned to disk
FactorsSize of all repositories
GuidelineGreater than 20% free space accounting for the size of all repositories on disk, including soft-deleted repositories
It can also be customized via a variable named SRC_REPOS_DESIRED_PERCENT_FREE
Update disk size of indexserver per adjustments made for gitserver disk size
TypePersistent Volumes for Kubernetes
Persistent SSD for Docker Compose

grafana

SHELL
A Grafana instance that displays data from Prometheus and Jaeger. It is shipped with customized dashboards for Sourcegraph services.
Resources
OverviewNot designed to be a high-traffic service
FactorsNumber of Site Admins
GuidelineThe default setup should be sufficient for most deployments

jeager

SHELL
A Jaeger instance for end-to-end distributed tracing
Resources
OverviewA debugging tool that is not designed to be a high-traffic service
FactorsNumber of Site Admins
GuidelineMemory depends on the size of buffers, like the number of traces and the size of the queue for example
The Jaeger service is not mandatory for basic Sourcegraph functionality, however, the ability to troubleshoot issues is vastly improved with it.

blobstore

SHELL
A blobstore instance that serves as local S3-compatible object storage. It holds files such as search jobs results and index uploads for precise code navigation.
Replica
OverviewSingleton
Factors-
GuidelineA Singleton service should not have more than 1 replica
CPU
OverviewThe default setup should be sufficient for most deployments
Factors-
Guideline-
Memory
OverviewThe default setup should be sufficient for most deployments
Factors-
Guideline-
Storage
OverviewA temporary storage location for the LSIF uploads
FactorsSize of the largest LSIF index
GuidelineEqual to the size of the largest LSIF index file
TypePersistent Volumes for Kubernetes
Persistent SSD for Docker Compose

pgsql

SHELL
The main database. A PostgreSQL instance. Data stored include repo lists, user data, worker queue , and site-config files etc. Data for code-insights related to running queries are also stored here. Basically anything not related to code-intel.
Replica
OverviewSingleton
Factors-
GuidelineA Singleton service should not have more than 1 replica
CPU
OverviewExecutes queries
FactorsThe default setup should be sufficient for most deployments
GuidelineThe database must be configured properly following our Postgres configuration guide to use the assigned resources efficiently
Memory
OverviewLinear to the concurrent number of API requests proxies
FactorsThe default setup should be sufficient for most deployments
GuidelineThe database must be configured properly following our Postgres configuration guide to use the assigned resources efficiently
Storage
OverviewThe Postgres instance will use memory by bringing OS pages into resident memory where it will control its own allocations
FactorsSize of all repositories
Number of insight queries
GuidelineStarts at default as the value grows depending on the number of active users and activity
The database must be configured properly following our Postgres configuration guide to use the assigned resources efficiently
TypePersistent Volumes for Kubernetes
Persistent SSD for Docker Compose
The database must be configured properly to consume resources effectively and efficiently for better performance and to avoid regular usage from overwhelming built-in utilities (like autovacuum for example). For example, a Postgres database running out of memory indicates that it is currently misconfigured and the amount of memory each worker can utilize should be reduced. See our Postgres database configuration guide for more information.

precise-code-intel

SHELL
Handles conversion of uploaded code graph data bundles. It converts LSIF upload file into Postgres data.
Replica
OverviewProcess uploads queue
FactorsNumber of jobs in the upload queue
GuidelineWhen there is a large queue backlog to increase the throughput at which uploads are processed
CPU
OverviewThis service is I/O bound: reading from blobstore/GCS/S3 and writing to pgsql/codeintel-db. Correlation has been fairly optimized
FactorsNumber of jobs in the upload queue
GuidelineUpload jobs may finish faster if the CPU is increased, but having it at a reasonable minimum should be the ideal target here
MEM
OverviewThe entire LSIF index file must be read into memory to be correlated, and causes uploads to fail when out of memory
FactorsSize of the largest LSIF index
GuidelineThe entire index must be read into memory to be correlated
Add memory when the uploaded index is too large to be processed without OOMing
Requires two times of the size of the largest LSIF index times upload_concurrency in memory
Storage
Overview-
Factors-
Guideline-
TypeNone

prometheus

SHELL
A customized Prometheus instance for collecting high-level and low-cardinality, metrics across services. It currently bundles Alertmanager as well as integrations to the Sourcegraph web application.
Resources
OverviewThe default setup should be sufficient for most deployments
FactorsNumber of active users
GuidelineFor Kubernetes deployments, please follow the instruction here to prevent Prometheus from scraping metrics outside of your Sourcegraph namespace

redis-cache

SHELL
A Redis instance for storing cache data for frontend.
Replica
OverviewSingleton
Factors-
GuidelineA Singleton service should not have more than 1 replica
CPU
OverviewThe default setup should be sufficient for most deployments
Factors-
Guideline-
Memory
OverviewThe default setup should be sufficient for most deployments
Factors-
Guideline-
Storage
OverviewA temporary storage location for cache data
FactorsSize of all repositories
GuidelineAdjust based on the size of cloned repositories
Depends on the size of the API response body
TypeEphemeral storage for Kubernetes
Persistent SSD for Docker Compose

redis-store

SHELL
A Redis instance for storing short-term information such as user sessions.
Replica
OverviewSingleton
Factors-
GuidelineA Singleton service should not have more than 1 replica
CPU
OverviewThe default setup should be sufficient for most deployments
Factors-
Guideline-
Memory
OverviewThe default setup should be sufficient for most deployments
FactorsNumber of active users
GuidelineIncrease memory based on the number of active user sessions (including both anonymous users and signed-in users)
Each anonymous session is counted independently
Storage
OverviewStores user sessions
FactorsSize of all repositories
GuidelineTIncrease based on the number of active user sessions (including both anonymous users and signed-in users
each anonymous session is counted independently
TypeEphemeral storage for Kubernetes
Persistent SSD for Docker Compose

repo-updater

SHELL
Repo-updater tracks the state of repositories. It is responsible for automatically scheduling updates using gitserver. It is also responsible for synchronizing metadata between code hosts and external services. Services that desire updates or fetch must communicate with repo-updater instead of gitserver.
Replica
OverviewSingleton
Factors-
GuidelineA Singleton service should not have more than 1 replica
CPU
OverviewMost operations are not CPU bound
FactorsMost of the syncing jobs are related more to internal and code host-specific rate limits
Guideline-
Memory
OverviewThe queue of repositories that need to be updated is stored in memory. It uses an in-memory queue and is mostly network intensive as it makes API calls and processes and writes those newly available data to the pgsql database
FactorsNumber of repositories
GuidelineThis service is safe to restart at any time. The existing in-memory update queue is reset upon restart
Not memory intensive
Storage
OverviewA stateless service that directly writes to the pgsql database
Factors-
Guideline-
TypeNone

searcher

SHELL
Provides on-demand unindexed search for repositories. It relies on the OS file page cache to speed up future searches
Replica
OverviewDepending on the number of concurrent requests for unindexed search
FactorsNumber of active users
GuidelineMore engaged users = more replicas
CPU
OverviewSearcher is IO and CPU bound. It fetches archives from gitserver and searches them with regexp
FactorsNumber of active users
GuidelineMore engaged users = more CPU
Memory
OverviewSearcher fetches archives from gitserver and stores them on disk
FactorsNumber of active users
GuidelineNot a memory-intensive service as the search results are streamed out
Memory usage is based on the number of concurrent search requests
More memory will be useful around page cache
Storage
OverviewSearcher primarily uses disk space to cache archives for unindexed search
FactorsSize of the largest repository
GuidelineRequires enough disk space to store the largest repository
The most important thing is to ensure fast IO for storage
Add more disks or replicas if you have lots of unindexed searches
More disk space will help speed up future caches
TypeEphemeral storage for Kubernetes deployments
The request size of the ephemeral storage is used as a limit for the zip cache
Non-persistent SSD for Docker Compose
For example, if you search all branches on all repositories, that translates into lots of concurrent unindexed requests.

symbols

SHELL
The backend for symbols operations. Indexes symbols in repositories using Ctags.
Replica
OverviewProcess unindexed search
FactorsNumber of active users
GuidelineMore requests for distinct commits in different repositories = more replica
CPU
OverviewRuns Ctags over code, stores symbol data in SQLite (or codeintel-db if using Rockskip)
FactorsSize of all repositories
GuidelineScale with the size of repositories
Memory
OverviewStores symbol data in SQLite and/or Postgres if Rockskip is enabled
FactorsSize of all repositories
GuidelineScale with the size of repositories
Storage
OverviewSaves SQLite DBs as files on disk in LRU fashion and copies an old one to a new file when a user visits a new commit
FactorsSize of the largest repository
GuidelineAt least 20% more than the size of your largest repository
Using SSD is highly preferred
TypeEphemeral storage for Kubernetes deployments
Non-persistent SSD for Docker Compose
If Rockskip is enabled, the symbols for repositories indexed by Rockskip are stored in codeintel-db instead.

syntect-server

SHELL
An HTTP server that exposes the Rust Syntect syntax highlighting library to other services.
Replica
OverviewThe constant overhead applies per worker process. Having a large number of processes is not necessarily useful (consumes more memory while idling) if there aren't many active users
FactorsNumber of active users
GuidelineMore users = more CPU and replicas
Add replica when syntax highlighting queries take a long duration because of existing traffic
CPU
OverviewThere are a number of worker processes, each with some number of threads. When a syntax highlighting request comes in, it is dispatched to a process, which further sends it to the worker thread. When there are no requests, CPU consumption should be minimal
FactorsNumber of active users
GuidelineMore users = more CPU and replicas
Memory
OverviewA lot of the highlighting themes and compiled grammars are loaded into memory at start up
FactorsNumber of active users
GuidelineThere is additional memory consumption on receiving requests (< 25 MB), although, that's generally much smaller than the constant overhead (1-2 GB)
Storage
Overview-
Factors-
Guideline-
TypeNone

worker

SHELL
Runs a collection of background jobs periodically in response to internal requests and external events.
See the docs on Worker services for a list of worker jobs.
Replica
OverviewSingleton
Factors-
GuidelineA Singleton service should not have more than 1 replica
CPU
OverviewOne goroutine per worker
FactorsNumber of repositories
Size of all repositories
Size of the largest repository
Number of insight series defined
GuidelineRate limited / concurrency limited worker pool
Memory
OverviewAbulating search results to generate Code Insights time series
FactorsNumber of repositories
Number of insight series defined
GuidelineGrow with the number of repositories and code-insight users
Storage
Overview-
Factors-
Guideline-
TypeNone

zoekt-indexserver

SHELL
Indexes all enabled repositories on Sourcegraph. It also keeps the indexes up to date. Lives inside the indexed-search pod in a Kubernetes deployment. The main guideline for scaling a zoekt-indexserver is the size of your largest repository.
As indexserver currently only indexes one repository at a time, having more CPU and memory are not as important here than in webserver.
Replica
OverviewParallel with zoekt-webserver
FactorsSize of the largest repository
GuidelineScales with zoekt-webserver
Replicas number must be parallel with zoekt-webserver
CPU
OverviewIndexes one repository at a time
FactorsSize of the largest repository
GuidelineMore CPU results in lower lag between a new commit and the time it takes to index for search
Memory
OverviewScans for symbols
FactorsSize of the largest repository
GuidelineIn general the amount of RAM used will max out at 100MB * number of CPUS * constant factor (around 5 in practice)
Storage
OverviewStores index. Storage is shared with zoekt-webserver
FactorsSize of all repositories
Guideline50% of the gitserver disk size
Disk IO is important as it constantly reads from disk during searches
Scale with zoekt-webserver
TypePersistent Volumes for Kubernetes
Persistent SSD for Docker Compose
We recommend providing zoekt-indexserver with more resources when trying to add a lot of new repositories that requires indexing from a new external service, and then scale down once indexing is completed.

zoekt-webserver

SHELL
Runs searches from indexes stored in memory and disk. It serves and processes data from zoekt-indexserver. The indexes are persisted to disk to avoid re-indexing on startup. Lives inside the indexed-search pod in a Kubernetes deployment.
Adding more CPU and memory helps speed up searches.
Replica
OverviewParallel with zoekt-indexserver
FactorsNumber of repositories
Size of all repositories
GuidelineMore repositories = more CPU and replicas
Replicas number must be parallel with zoekt-indexserver
CPU
OverviewGoroutines are dispatched per search query
FactorsNumber of repositories
Number of active users
GuidelineScales with the number of search requests
More search requests = more CPU and replicas
Memory
OverviewParts of the index are stored in memory
FactorsNumber of repositories
Size of all repositories
GuidelineScales with the number of repositories
More repositories = more memory
Storage
OverviewStores index. Storage is shared with zoekt-indexserver.
FactorsSize of all repositories
Guideline50% of the gitserver disk size
Disk IO is important as it constantly reads from disk during searches
Scale with zoekt-indexserver
TypePersistent Volumes for Kubernetes
Persistent SSD for Docker Compose
Check the peak bursts rather than the average over time when monitoring CPU usage for zoekt as it depends on when the searches happen.