Amazon Neptune¶
Service Overview and Purpose¶
Amazon Neptune is a fully managed graph database service that supports both property graph and RDF graph models. Neptune is optimized for storing billions of relationships and querying the graph with milliseconds latency.
Key Characteristics¶
- Graph Database: Optimized for highly connected data
- Multi-Model: Property graphs (Gremlin) and RDF (SPARQL)
- High Performance: Low latency graph traversals
- Fully Managed: Automated administration tasks
- ACID Compliant: Full transaction support
Key Features and Capabilities¶
Graph Models¶
- Property Graphs: Vertices and edges with properties (Apache TinkerPop Gremlin)
- RDF Graphs: Resource Description Framework with SPARQL queries
- ACID Transactions: Ensure data consistency
- Graph Algorithms: Built-in graph algorithms and ML capabilities
Architecture¶
- Cluster-Based: Primary instance and up to 15 read replicas
- Storage: Purpose-built graph storage layer
- Multi-AZ: High availability across availability zones
- Global Database: Cross-region replication
Configuration and Use Cases¶
Cluster Creation¶
aws neptune create-db-cluster \
--db-cluster-identifier neptune-social-graph \
--engine neptune \
--master-username admin \
--master-user-password SecurePassword123! \
--vpc-security-group-ids sg-12345678 \
--db-subnet-group-name neptune-subnet-group \
--backup-retention-period 7 \
--storage-encrypted \
--enable-cloudwatch-logs-exports audit \
--tags Key=Environment,Value=Production
Gremlin Query Examples¶
from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
# Connect to Neptune
graph = Graph()
g = graph.traversal().withRemote(
DriverRemoteConnection('wss://neptune-cluster.cluster-xyz.us-west-2.neptune.amazonaws.com:8182/gremlin', 'g')
)
# Add vertices and edges
user1 = g.addV('User').property('name', 'Alice').property('age', 30).next()
user2 = g.addV('User').property('name', 'Bob').property('age', 25).next()
g.addE('knows').from_(user1).to(user2).property('since', '2023-01-01').next()
# Query relationships
friends_of_alice = g.V().has('name', 'Alice').out('knows').values('name').toList()
# Complex graph traversals
mutual_friends = g.V().has('name', 'Alice').out('knows').out('knows').where(
__.not_(__.path().by('name').is_(['Alice']))
).dedup().values('name').toList()
Use Cases and Scenarios¶
Primary Use Cases¶
- Social Networks: Friend recommendations, influence analysis
- Fraud Detection: Pattern recognition in financial transactions
- Recommendation Engines: Product and content recommendations
- Knowledge Graphs: Entity relationships and semantic search
- Network Analysis: IT infrastructure, supply chain optimization
Common Exam Scenarios¶
- Social Media Applications: Friend networks and recommendations
- Fraud Detection Systems: Complex relationship analysis
- Real-Time Recommendations: Graph-based recommendation engines
- Knowledge Management: Semantic data relationships
Exam Tips¶
- Know graph database concepts and when to use them
- Understand supported query languages (Gremlin and SPARQL)
- Remember use cases for highly connected data
- Know integration with other AWS services for analytics
- Understand performance characteristics for graph queries