Replicas, Failover, Snapshots, PITR and Analytics

Article · 8:00

Read replicas and multi-AZ, failover behaviour and priorities, snapshots and point-in-time recovery, cloning, and what Neptune Analytics is for.

Multi-AZ is a replica in another availability zone, and it is what makes failover meaningful. The storage layer is already replicated across three zones, so storage survives a zone loss regardless - what a replica in another zone gives you is a compute instance to promote. A cluster with a writer and no replica survives a zone failure with its data intact and no instance to serve it until a new one is provisioned, which is minutes rather than under a minute.

Failover behaviour is worth knowing precisely. Neptune promotes a replica, typically in under a minute (often around 30 seconds), with no data loss because the storage was shared. The cluster endpoint's DNS is updated to the new writer, so an application using the cluster endpoint recovers automatically - though it must handle the connection errors during the window and re-resolve DNS, which is the same lesson as Module 4. Failover priority (tier 0 to 15) controls which replica is chosen, and setting it deliberately matters when your replicas are not the same size.

Snapshots are cluster-wide, consistent, incremental in storage terms, and restore to a new cluster. Automated snapshots run daily with a configurable retention of up to 35 days; manual snapshots persist until deleted. The important properties: a restore creates a new cluster, so the runbook needs a cutover step; the restored cluster has default parameter groups and security groups unless you specify them, which is a trap worth knowing; and the restored cluster's instances must be created, which takes time.

Point-in-time recovery restores to any second within the backup retention window, which is the mechanism that recovers you from a bad load or a destructive query - the realistic Neptune incident. As with snapshots, it creates a new cluster.

Cloning is the feature worth knowing about: a clone shares the source's storage using copy-on-write, so it is created in minutes regardless of data size and costs only the storage that diverges. That makes it the right way to get a production-sized environment for testing a migration, a new query or a destructive change. It is one of the genuinely useful managed-service features in this programme.

Neptune Analytics is a separate service and the distinction matters. The transactional engine has no graph algorithms. Neptune Analytics is an in-memory analytics engine that runs algorithms - PageRank, community detection, centrality, shortest paths, vector similarity - over a graph loaded from S3 or from a Neptune cluster snapshot. It is not a replacement for the cluster and not where your transactional workload goes: you load a snapshot of the graph, run the analysis, and use the results. So the architecture for "we need PageRank" is two services and a data movement step, and a design that assumed otherwise needs revisiting.

Laboratory exercise 5 - break it, then get it back.

Add a read replica in a second availability zone and set failover priorities.

Force a failover under write load and measure: the time to promotion, the window in which writes failed, the number of client errors, and whether any acknowledged write was lost (it should be zero). Then do the same with an application using an instance endpoint instead of the cluster endpoint and show it not recovering.

Measure the replica lag under load, and correlate it with the miss rate you measured in Module 3.

Perform a destructive change at a recorded time - a bad bulk load, or a query that deletes a label's worth of vertices. Then recover three ways and compare: a point-in-time restore, a restore from a snapshot, and a reload from S3. Time each, and record RPO and RTO.

Demonstrate the restore trap: restore a snapshot without specifying the parameter group and security group, and enumerate what came back different.

Create a clone and record how long it took and what it cost, then make a destructive change in the clone and confirm the source is untouched.

Finally, for Neptune Analytics, either load a graph and run PageRank and a community detection algorithm, recording the load time and the results; or produce a design exercise describing the two-service architecture, the data movement, the freshness implication and the cost.

Deliverable: the failover measurements for both endpoint types, the replica lag correlated with the Module 3 miss rate, the three recovery methods with measured RPO and RTO, the enumerated restore trap, the clone timing and cost, and either the Analytics results or the design exercise.

# ==================================================================
# MULTI-AZ: the storage is already replicated. A replica gives you
# AN INSTANCE TO PROMOTE.
# ==================================================================
#   aws neptune create-db-instance \
#     --db-instance-identifier identity-graph-reader-2 \
#     --db-cluster-identifier identity-graph \
#     --db-instance-class db.serverless --engine neptune \
#     --availability-zone eu-west-2b \
#     --promotion-tier 1
#                      ^^^ FAILOVER PRIORITY, 0-15. Lower wins.
#                      Set it deliberately when your replicas are
#                      not the same size - otherwise you can fail
#                      over onto something too small.
#
# *** A cluster with a WRITER AND NO REPLICA survives a zone failure
# *** WITH ITS DATA INTACT and NO INSTANCE TO SERVE IT until a new
# *** one is provisioned - MINUTES rather than under a minute. ***
# That is the whole argument for multi-AZ here: not durability, which
# the storage layer already provides, but RECOVERY TIME.

# ==================================================================
# FAILOVER, precisely.
# ==================================================================
#   aws neptune failover-db-cluster \
#     --db-cluster-identifier identity-graph \
#     --target-db-instance-identifier identity-graph-reader-1
#
#   * a replica is promoted, typically in UNDER A MINUTE (often ~30 s)
#   * *** NO DATA LOSS *** - the storage was shared
#   * THE CLUSTER ENDPOINT'S DNS IS UPDATED to the new writer
#
# SO AN APPLICATION USING THE CLUSTER ENDPOINT RECOVERS
# AUTOMATICALLY - provided it:
#   * handles the connection errors during the window, and
#   * RE-RESOLVES DNS (the Module 4 lesson, again)
#
# DEMONSTRATE BOTH: fail over with an application on the CLUSTER
# endpoint (recovers) and one on an INSTANCE endpoint (does not).
# The second is the mistake, and seeing it fail is the lesson.
#
#   CloudWatch during the failover:
#     NeptuneReplicaLag, NumConnections, GremlinHttp5xx
#   and count ACKNOWLEDGED WRITES LOST: should be ZERO.

# ==================================================================
# SNAPSHOTS: cluster-wide, consistent, restore to a NEW cluster.
# ==================================================================
#   aws neptune create-db-cluster-snapshot \
#     --db-cluster-identifier identity-graph \
#     --db-cluster-snapshot-identifier identity-graph-20261130
#
#   automated: daily, retention up to 35 days
#   manual:    persists until you delete it
#
#   aws neptune restore-db-cluster-from-snapshot \
#     --db-cluster-identifier identity-graph-restored \
#     --snapshot-identifier identity-graph-20261130 \
#     --engine neptune \
#     --db-subnet-group-name neptune-subnets \
#     --vpc-security-group-ids sg-abc123 \
#     --db-cluster-parameter-group-name identity-graph-params
#
# *** THE RESTORE TRAP: WITHOUT THOSE LAST THREE ARGUMENTS THE
# *** RESTORED CLUSTER GETS DEFAULT PARAMETER GROUPS AND SECURITY
# *** GROUPS. *** Which means: your query timeout is back to the
# default, your audit logging is off, and your security group may
# not allow your application. Demonstrate it, and ENUMERATE what
# came back different - then put the full command in the runbook.
#
# AND: a restore creates the CLUSTER; you must then CREATE THE
# INSTANCES, which takes time and is part of your RTO:
#   aws neptune create-db-instance --db-cluster-identifier identity-graph-restored ...

# ==================================================================
# POINT-IN-TIME RECOVERY: any second in the retention window.
# ==================================================================
#   aws neptune restore-db-cluster-to-point-in-time \
#     --db-cluster-identifier identity-graph-pitr \
#     --source-db-cluster-identifier identity-graph \
#     --restore-to-time 2026-11-30T14:04:00Z \
#     --db-subnet-group-name neptune-subnets \
#     --vpc-security-group-ids sg-abc123 \
#     --db-cluster-parameter-group-name identity-graph-params
#
#   aws neptune describe-db-clusters --db-cluster-identifier identity-graph \
#     --query 'DBClusters[0].EarliestRestorableTime'
#
# *** THIS IS THE MECHANISM THAT RECOVERS YOU FROM A BAD LOAD OR A
# *** DESTRUCTIVE QUERY - THE REALISTIC NEPTUNE INCIDENT. *** Not a
# zone failure, which the service handles; a bad bulk load with
# failOnError FALSE that half-loaded the wrong data, or a query that
# deleted a label's worth of vertices.

# ==================================================================
# *** CLONING: the genuinely useful one. ***
# ==================================================================
#   aws neptune restore-db-cluster-to-point-in-time \
#     --db-cluster-identifier identity-graph-clone \
#     --source-db-cluster-identifier identity-graph \
#     --restore-type copy-on-write --use-latest-restorable-time \
#     --db-subnet-group-name neptune-subnets \
#     --vpc-security-group-ids sg-abc123
#                    ^^^^^^^^^^^^^ COPY-ON-WRITE
#
#   A clone SHARES THE SOURCE'S STORAGE, so it is created in MINUTES
#   REGARDLESS OF DATA SIZE and costs only the storage that
#   DIVERGES.
#
# *** WHICH MAKES IT THE RIGHT WAY TO GET A PRODUCTION-SIZED
# *** ENVIRONMENT for testing a migration, a new query, or a
# *** destructive change. *** One of the genuinely useful
# managed-service features in this programme - and the lab should
# confirm it: clone, destroy data in the clone, verify the source is
# untouched.

# ==================================================================
# *** NEPTUNE ANALYTICS IS A SEPARATE SERVICE. ***
# ==================================================================
# The TRANSACTIONAL engine has NO GRAPH ALGORITHMS. None.
#
# Neptune Analytics is an IN-MEMORY analytics engine that runs
# algorithms over a graph loaded from S3 or from a Neptune snapshot:
#   PageRank, community detection (label propagation), centrality
#   (degree, closeness, betweenness), shortest paths, and vector
#   similarity.
#
#   aws neptune-graph create-graph --graph-name identity-analytics \
#     --provisioned-memory 16 --replica-count 0
#   aws neptune-graph create-graph-using-import-task \
#     --graph-name identity-analytics \
#     --source s3://my-bucket/identity/ --format CSV \
#     --role-arn arn:aws:iam::111122223333:role/NeptuneGraphImport
#
#   %%oc  (against the Analytics endpoint)
#   CALL neptune.algo.pageRank.mutate({writeProperty: 'rank'})
#   CALL neptune.algo.labelPropagation.mutate({writeProperty: 'community'})
#   MATCH (p:Person) RETURN p.name, p.rank ORDER BY p.rank DESC LIMIT 20
#
# *** IT IS NOT A REPLACEMENT FOR THE CLUSTER and NOT WHERE YOUR
# *** TRANSACTIONAL WORKLOAD GOES. *** You LOAD A SNAPSHOT, RUN THE
# ANALYSIS, and USE THE RESULTS.
#
# SO THE ARCHITECTURE FOR "WE NEED PAGERANK" IS TWO SERVICES AND A
# DATA MOVEMENT STEP, with three consequences a design must state:
#   1. the analysis is AS FRESH AS THE LAST LOAD, not live
#   2. the second service is a SEPARATE COST, billed by memory
#   3. writing results BACK to the transactional cluster is YOUR job
#
# A design that assumed the cluster could do PageRank needs
# revisiting, and this is where that is discovered.

# ==================================================================
# VERIFY A RECOVERY WITH ASSERTIONS.
# ==================================================================
%%gremlin
g.V().groupCount().by(label)
%%gremlin
g.E().groupCount().by(label)
%%oc
MATCH (n) RETURN labels(n)[0] AS label, count(*) AS n ORDER BY n DESC
#   ... then the capstone invariants. "The cluster is available" is
#   not verification - and check the PARAMETER GROUP too, because
#   the restore trap means the cluster may be running with defaults.
#   aws neptune describe-db-clusters --db-cluster-identifier identity-graph-restored \
#     --query 'DBClusters[0].[DBClusterParameterGroup,VpcSecurityGroups]'

Discussion

No questions on this topic yet. Sign in to ask the first one.