Clusters, Endpoints, Notebooks and the VPC

Article · 7:00

Cluster architecture, writer and reader endpoints, the VPC constraint, notebooks, the three query language endpoints, and the limits that bound a design.

The cluster separates compute from storage, in the same shape as Aurora. One writer instance accepts writes; zero or more read replicas serve reads; all of them share a distributed storage volume replicated six ways across three availability zones. The consequences: a replica does not hold its own copy, so adding one is fast; a replica failing loses nothing; storage grows automatically; and a failover promotes a replica in typically under a minute without data loss, because the storage was never the replica's.

Three endpoints, and using the wrong one is a common mistake. The cluster endpoint always points at the current writer and is what your write path uses - it follows a failover automatically. The reader endpoint load-balances across the replicas, and it is DNS-based round-robin, so it does not balance per request and a long-lived connection stays on one replica. Instance endpoints address one instance directly, which you need for pinning a workload to a specific replica.

Neptune is inside a VPC and has no public endpoint, full stop. There is no "allow my IP" option. You reach it from a Neptune notebook (a managed Jupyter environment in the same VPC), from an EC2 instance or container in the VPC, through a VPN or Direct Connect, or through a bastion with port forwarding. This is the first laboratory, and underestimating it is the commonest way a first Neptune session is spent entirely on networking.

Neptune notebooks are the right exploration tool. They provide %%gremlin, %%oc and %%sparql cell magics, a graph visualiser, and %status, %load and %summary line magics that wrap the management API. They cost money while running and are worth it for the laboratory work.

Three query endpoints on the same cluster. /gremlin (WebSocket or HTTP), /openCypher (HTTP) and /sparql (HTTP). Gremlin and openCypher both operate on the property graph store; SPARQL operates on the RDF store. They are separate stores, and that is the subject of Module 2.

The limits that bound a design:

  • No local emulator, so every laboratory costs money.
  • Instance size determines the connection limit and the query concurrency, and both are lower than people expect on small instances - a t3.medium Serverless minimum will refuse connections under load you would consider modest.
  • Query timeout defaults to 120 seconds and is configurable per cluster, which is your protection against an unbounded traversal.
  • There is no user-defined function or stored procedure mechanism - the logic lives in your application.
  • No graph algorithms library on the transactional engine. Neptune Analytics is a separate service.

Laboratory exercise 1 - provision and reach it.

Provision a Neptune cluster - Serverless with a low minimum capacity is the cheapest useful choice - with one writer and one replica, and a Neptune notebook in the same VPC. Write the teardown procedure first and verify it works.

Record: the engine version, the instance class or capacity range, the cluster, reader and instance endpoints, the VPC, subnets and security group rules, the parameter group settings including the query timeout, and the backup retention.

Then prove the VPC constraint: attempt to reach the cluster endpoint from outside the VPC and capture the failure. Then reach it from the notebook and succeed.

Load at least 200,000 vertices and 800,000 edges modelling the capstone's identity graph, using the bulk loader from S3 - which needs an IAM role and an S3 VPC endpoint, both of which are part of the exercise.

Then demonstrate the endpoints: write through the cluster endpoint, read through the reader endpoint, and read through an instance endpoint, confirming each works. Then demonstrate the reader endpoint's behaviour: open ten connections through it and record which instances they landed on.

Finally, run the same trivial query through all three query endpoints - /gremlin, /openCypher and /sparql - and record that the first two see your data and the third sees nothing.

Deliverable: a reproducible provisioning script (CloudFormation or CDK) with the teardown, the recorded configuration, the external-access failure, the bulk load evidence, the three endpoint demonstrations with the connection distribution, and the three-query-endpoint result showing the separate stores.

# ==================================================================
# Provisioning. Serverless with a LOW MINIMUM is the cheapest useful
# configuration for this course.
# ==================================================================
#   aws neptune create-db-cluster \
#     --db-cluster-identifier identity-graph \
#     --engine neptune --engine-version 1.3.2.0 \
#     --vpc-security-group-ids sg-abc123 \
#     --db-subnet-group-name neptune-subnets \
#     --serverless-v2-scaling-configuration MinCapacity=1,MaxCapacity=8 \
#     --iam-database-authentication-enabled \
#     --storage-encrypted --kms-key-id alias/aws/rds \
#     --backup-retention-period 7 \
#     --enable-cloudwatch-logs-exports audit
#
#   aws neptune create-db-instance \
#     --db-instance-identifier identity-graph-writer \
#     --db-cluster-identifier identity-graph \
#     --db-instance-class db.serverless --engine neptune
#   aws neptune create-db-instance \
#     --db-instance-identifier identity-graph-reader-1 \
#     --db-cluster-identifier identity-graph \
#     --db-instance-class db.serverless --engine neptune
#
# *** WRITE THE TEARDOWN FIRST AND VERIFY IT WORKS: ***
#   aws neptune delete-db-instance --db-instance-identifier identity-graph-reader-1 --skip-final-snapshot
#   aws neptune delete-db-instance --db-instance-identifier identity-graph-writer --skip-final-snapshot
#   aws neptune delete-db-cluster --db-cluster-identifier identity-graph --skip-final-snapshot
#   aws neptune describe-db-cluster-snapshots   # delete these too
#   ... and the NOTEBOOK, and the NAT GATEWAY if you created one.
#
# A Neptune cluster left running is a meaningful bill. A NAT gateway
# left running is a surprising one.

# ==================================================================
# ARCHITECTURE: compute separated from storage, as Aurora.
# ==================================================================
#   WRITER        accepts writes. One.
#   READ REPLICAS serve reads. Zero or more, up to 15.
#   STORAGE       a shared distributed volume, replicated SIX WAYS
#                 across THREE availability zones.
#
#   CONSEQUENCES:
#     * a replica does NOT hold its own copy, so ADDING ONE IS FAST
#     * a replica failing LOSES NOTHING
#     * storage grows automatically
#     * *** FAILOVER PROMOTES A REPLICA IN TYPICALLY UNDER A MINUTE
#       WITH NO DATA LOSS *** - because the storage was never the
#       replica's in the first place

# ==================================================================
# *** THREE ENDPOINTS. Using the wrong one is a common mistake. ***
# ==================================================================
#   aws neptune describe-db-clusters --db-cluster-identifier identity-graph \
#     --query 'DBClusters[0].[Endpoint,ReaderEndpoint]'
#
#   CLUSTER endpoint   identity-graph.cluster-abc.eu-west-2.neptune.amazonaws.com
#     -> ALWAYS the current WRITER. Your write path uses this, and it
#        FOLLOWS A FAILOVER automatically.
#
#   READER endpoint    identity-graph.cluster-ro-abc...
#     -> load-balances across the replicas. *** AND IT IS DNS-BASED
#        ROUND-ROBIN, so it does NOT balance PER REQUEST: a
#        long-lived connection STAYS ON ONE REPLICA. ***
#        Demonstrate it - open ten connections and see where they
#        land. An application with a connection pool created at
#        startup may have every connection on one replica.
#
#   INSTANCE endpoints identity-graph-reader-1.abc...
#     -> ONE instance directly. Needed to pin a workload to a
#        specific replica, which is how you isolate a heavy query.

# ==================================================================
# *** NEPTUNE IS INSIDE A VPC AND HAS NO PUBLIC ENDPOINT. ***
# ==================================================================
# Full stop. There is no "allow my IP" option. You reach it from:
#   * a NEPTUNE NOTEBOOK in the same VPC   <- do this
#   * an EC2 instance or container in the VPC
#   * a VPN or Direct Connect
#   * a bastion with port forwarding:
#       ssh -L 8182:identity-graph.cluster-abc...:8182 ec2-user@bastion
#
# *** THIS IS THE FIRST LABORATORY, NOT AN ASIDE. *** Underestimating
# it is the commonest way a first Neptune session is spent entirely
# on networking. Prove the constraint: curl the endpoint from your
# laptop and capture the timeout.

# A NEPTUNE NOTEBOOK - the right exploration tool:
#   aws neptune-graph ... / the console's Notebooks section
#   Cell magics:  %%gremlin   %%oc   %%sparql
#   Line magics:  %status  %load  %summary  %graph_notebook_config
#   Plus a graph visualiser, which is worth having.

# ==================================================================
# *** THREE QUERY ENDPOINTS, TWO SEPARATE STORES. ***
# ==================================================================
#   POST https://<endpoint>:8182/gremlin      property graph
#   POST https://<endpoint>:8182/openCypher   property graph
#   POST https://<endpoint>:8182/sparql       RDF
#
#   Gremlin and openCypher see THE SAME property graph.
#   SPARQL sees A DIFFERENT STORE.
#
# Demonstrate it in the lab. Load property graph data, then:
#   %%gremlin
#   g.V().count()
#   -> 200000
#
#   %%oc
#   MATCH (n) RETURN count(n)
#   -> 200000      (the same store)
#
#   %%sparql
#   SELECT (COUNT(*) AS ?n) WHERE { ?s ?p ?o }
#   -> 0           *** A DIFFERENT STORE. Nothing is there. ***
#
# That result is Module 2's whole subject, and seeing it in Module 1
# prevents a very expensive misunderstanding.

# ==================================================================
# BULK LOAD FROM S3. This is how you load Neptune.
# ==================================================================
# It needs an IAM ROLE attached to the cluster AND an S3 VPC
# ENDPOINT - both part of the exercise, and both a common first
# failure.
#
#   curl -X POST https://<endpoint>:8182/loader \
#     -H 'Content-Type: application/json' -d '{
#       "source": "s3://my-bucket/identity/",
#       "format": "csv",
#       "iamRoleArn": "arn:aws:iam::111122223333:role/NeptuneLoadFromS3",
#       "region": "eu-west-2",
#       "failOnError": "FALSE",
#       "parallelism": "HIGH",
#       "updateSingleCardinalityProperties": "FALSE"
#     }'
#   -> {"status":"200 OK","payload":{"loadId":"abc-123"}}
#
#   curl -G https://<endpoint>:8182/loader/abc-123 \
#     --data-urlencode 'details=true' --data-urlencode 'errors=true'
#   -> status, recordsProcessed, and THE ERROR LIST
#
# *** READ THE ERRORS. *** With failOnError FALSE a load "succeeds"
# with thousands of rejected rows, and the only way to know is to
# ask. A load that reports 200 OK and loaded 40% of your data is the
# characteristic first-attempt outcome.
#
#   CSV header format (Gremlin):
#     vertices: ~id,~label,name:String,email:String
#     edges:    ~id,~from,~to,~label,since:Date
#   openCypher load format differs slightly:
#     :ID,:LABEL,name:String
#     :START_ID,:END_ID,:TYPE,since:DateTime

# ==================================================================
# THE LIMITS THAT BOUND A DESIGN.
# ==================================================================
#   * NO LOCAL EMULATOR. Every laboratory costs money.
#   * *** INSTANCE SIZE DETERMINES THE CONNECTION LIMIT AND QUERY
#     CONCURRENCY, and both are LOWER THAN PEOPLE EXPECT on small
#     instances. *** A Serverless minimum of 1 NCU will refuse
#     connections under load you would consider modest. Measure
#     yours before you benchmark anything else.
#   * QUERY TIMEOUT defaults to 120 s, configurable per cluster via
#     the parameter group (neptune_query_timeout, in milliseconds).
#     *** This is your protection against an unbounded traversal. ***
#   * NO user-defined functions and NO stored procedures. The logic
#     lives in your application.
#   * *** NO GRAPH ALGORITHMS LIBRARY on the transactional engine. ***
#     No PageRank, no community detection, no Dijkstra. NEPTUNE
#     ANALYTICS is a SEPARATE SERVICE for that (Module 5).
#
#   aws neptune describe-db-cluster-parameters \
#     --db-cluster-parameter-group-name identity-graph-params

Discussion

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