# Memgraph in mission-critical workloads


> **Info**
>
> Before diving into this guide, we recommend starting with the [Best
> practices](https://memgraph.com/docs/deployment/best-practices)
>
> page. It provides **foundational, use-case-agnostic advice** for deploying
> Memgraph in production.
>
> This guide builds on that foundation, offering **additional recommendations
> tailored to critical and high-availability workloads**. In cases where guidance
> overlaps, consider the information here as **complementary or overriding**,
> depending on the unique needs of your use case.


## Is this guide for you?

This guide is for you if you're building **mission-critical systems** where
uptime, data consistency, and fault tolerance are essential.  You’ll benefit
from this content if:

- You require **high availability** and **automatic failover** for your
  application.  
- You need **strong consistency guarantees** even under heavy loads.  
- You must **recover gracefully** from unexpected failures without data loss.  
- You need to **support multi-tenant environments** securely across multiple
  projects or customers.


If this matches your needs, this guide will help you configure and operate
Memgraph to meet the demands of **always-on production environments**.

## Why choose Memgraph for mission-critical use cases?

When stability, consistency, and resilience matter most, Memgraph is built to
deliver. Here's why Memgraph is a great fit for mission-critical workloads:

- **In-memory storage engine with persistence** Memgraph keeps the working set
  fully in memory for fast access, while ensuring
  [durability](https://memgraph.com/docs/fundamentals/data-durability) through **periodic snapshots** and
  **write-ahead logging (WALs)** in transactional mode.

  Keeping the data in memory ensures lightning speed in times when you expect
  everything to function seamlessly and without issues during peak times of your
  critical service.

- **High availability with automatic failover** Memgraph supports full [high
  availability clustering](https://memgraph.com/docs/clustering/high-availability), allowing you to
  deploy **multiple instances** with automatic **leader election** and
  **failover** when needed.

  Deploying Memgraph with high availability will ensure Memgraph is up and
  running at all times, without compromising uptime of your services.

- **Multi-version concurrency control (MVCC)** Built on **MVCC**, Memgraph
  allows **non-blocking reads and writes**, ensuring that your system remains
  **responsive** even under concurrent access. Writes are not blocking reads,
  and vice versa.

- **Snapshot isolation by default** Memgraph uses **snapshot isolation** instead
  of **read-committed** isolation, preventing dirty reads and guaranteeing a
  **consistent view** of the graph at all times.

- **Replication for read scaling and redundancy** Memgraph supports
  **asynchronous replication**, enabling you to **scale read workloads**
  independently while ensuring **failover readiness**. For a more consistent
  view of the data, it also supports **synchronous replication** which
  prioritizes consistency over scalability.

- **Fine-grained access control and security** Secure your system with
  [**role-based access
 control**](https://memgraph.com/docs/database-management/authentication-and-authorization/role-based-access-control)
 and [**label-based access
 control**](https://memgraph.com/docs/database-management/authentication-and-authorization/role-based-access-control#label-based-access-control)
 to ensure only the right users see and manipulate data.

## What is covered?

The suggestions for mission-critical workloads **complement** several key
sections in the [general suggestions guide](https://memgraph.com/docs/deployment/best-practices), with
additional best practices to ensure uptime and data protection:

- [Choosing the right Memgraph flag set](#choose-the-right-memgraph-flag-set)  
  Memgraph offers flags to enhance recovery, snapshot management, and failover
  capabilities.

- [Choosing the right Memgraph storage
  mode](#choose-the-right-memgraph-storage-mode)  
  Guidance on selecting the **safest** and **most consistent** storage
  configurations.

- [Enterprise features you might
  require](#enterprise-features-you-might-require)  
  Overview of **replication**, **multi-tenancy**, and **automatic failover**
  tools that are critical in production.

- [Backup and recovery mechanisms](#backup-and-recovery-mechanisms)  
  Best practices to protect your data through snapshots, WALs, and external
  backup strategies.

- [Queries that best suit your workload](#queries-that-best-suit-your-workload)  
  Designing queries that maintain consistent, safe, and predictable behavior in
  high-availability systems.

## Choose the right Memgraph flag set


For mission-critical setups, you should configure Memgraph to optimize for **durability, fast recovery**, and **stability**. Some important flags include:

- `--storage-snapshot-interval-sec=x`  
  Set how often snapshots are created. In mission-critical systems, you may want
  **frequent snapshots** to minimize recovery time.

- `--storage-wal-enabled=true`  
  Ensure **WALs (write-ahead logs)** are enabled to protect all transactions
  between snapshots.

- `--storage-parallel-schema-recovery=true` and
  `--storage-recovery-thread-count=x`  
  Enable **parallel recovery** to speed up startup time after a crash by using
  multiple cores.

- `--query-execution-timeout-sec=x`  
  Set reasonable query timeouts to **avoid stuck queries** and prevent resource
  exhaustion.`

## Choose the right Memgraph storage mode


For mission-critical deployments:

- Always use `IN_MEMORY_TRANSACTIONAL` mode.  
- This mode provides **full ACID guarantees**, **WAL support**, and **snapshot
  consistency**.


> **Info**
>
> `IN_MEMORY_ANALYTICAL` is optimized for high-speed ingestion but does **not
> provide transactional durability**. It is not recommended for mission-critical
> workloads.


## Importing mechanisms

Importing mechanisms are best described in the [guide for high-throughput
workloads](https://memgraph.com/docs/deployment/workloads/memgraph-in-high-throughput-workloads). The
rule of thumb is to always setup the drivers to perform retries if you're doing
heavy amount of writes, in order to avoid read conflicts. The high throguhput
guide also outlines the need for idempotent queries, to ensure data consistency
if writes fail for any reason.

## Enterprise features you might require

For robust production environments, consider enabling:

- [High availability clustering](https://memgraph.com/docs/clustering/high-availability): Deploy multiple
  Memgraph instances with automatic leader election and failover.

- [Replication for resilience](https://memgraph.com/docs/clustering/replication): Distribute replicas
  geographically or across availability zones to minimize the risk of localized
  outages.

- [Role-based and label-based access
  control](https://memgraph.com/docs/database-management/authentication-and-authorization/role-based-access-control):
  Protect sensitive graph data and ensure only authorized operations are
  performed.

- [Multi-tenancy](https://memgraph.com/docs/database-management/multi-tenancy): Securely isolate data and
  permissions between different teams, projects, or customers.

## Backup and recovery mechanisms

Data durability is critical in mission-critical environments. Memgraph supports:

- [Snapshots](https://memgraph.com/docs/fundamentals/data-durability#snapshots)  
  Automatically or manually triggered full-database snapshots.

- [Write-ahead logging
  (WALs)](https://memgraph.com/docs/fundamentals/data-durability#write-ahead-logging)  
  Transaction logs that enable you to **replay changes** made after the last
  snapshot.

- **Manual backup and offloading**  
  Use external tools (like [`rclone`](https://rclone.org/)) to back up snapshots
  and WALs to **cloud storage** or **remote servers** for additional redundancy.



> **Info**
>
> Memgraph currently does not automate backing up data to 3rd party locations, so
> integrating a backup process into your system is highly recommended.



> **Info**
>
> Learn more about backup and restore [on our backup and restore documentation
> page](https://memgraph.com/docs/database-management/backup-and-restore).


## Queries that best suit your workload

In mission-critical workloads:

- Prefer **idempotent writes** (`MERGE`) to avoid inconsistent state during
  retries.
- Optimize long-running queries and [profile](https://memgraph.com/docs/querying/clauses/profile) them
  regularly.

- Avoid complex, unpredictable queries inside critical transactional paths.
- Use **schema constraints** and **indexes** wisely to enforce data integrity
  without hurting performance.

Example of safe, idempotent data ingestion:

```cypher
MERGE (n:Customer {id: $id})
SET n += $props;
```
