Learn Gremlin - 10 Code Examples & CST Typing Practice Test
Gremlin is a graph traversal language and virtual machine used across the Apache TinkerPop graph computing framework. It supports imperative and functional traversal steps to query, analyze, and mutate property graph data across both OLTP and OLAP graph systems.
Learn GREMLIN with Real Code Examples
Updated Nov 18, 2025
Code Sample Descriptions
Basic Gremlin Traversals
g.V().has("person", "name", "Alice")
.out("knows")
.values("name")
Traversing a graph to find friends of a person using Gremlin.
Add Vertex and Edge
g.addV("person").property("name", "Alice")
.addV("person").property("name", "Bob")
.addE("knows").from(g.V().has("name","Alice")).to(g.V().has("name","Bob"))
Adding vertices and an edge between them in Gremlin.
Filter by Property
g.V().hasLabel("person").has("age", gt(30)).values("name")
Finding people older than 30 in a Gremlin graph.
Shortest Path Traversal
g.V().has("person","name","Alice")
.repeat(out().simplePath()).until(has("person","name","Bob"))
.path()
Finding a simple path between two people.
Group By Property
g.V().hasLabel("person")
.group().by("city")
.next()
Grouping people by their city property.
Order Vertices
g.V().hasLabel("person")
.order().by("age", decr)
.values("name","age")
Ordering people by age in descending order.
Limit Traversal Results
g.V().hasLabel("person").limit(5).values("name")
Limiting the traversal to return only 5 people.
Remove Vertex
g.V().has("person","name","Alice").drop()
Deleting a vertex with a given property.
Traversal with Both Directions
g.V().has("person","name","Alice")
.both("knows")
.values("name")
Finding all friends connected in both directions.
Frequently Asked Questions about Gremlin
What is Gremlin?
Gremlin is a graph traversal language and virtual machine used across the Apache TinkerPop graph computing framework. It supports imperative and functional traversal steps to query, analyze, and mutate property graph data across both OLTP and OLAP graph systems.
What are the primary use cases for Gremlin?
Multi-hop graph traversals. Pattern search across large graphs. Fraud ring analysis. Network and IT topology mapping. Recommendation engines. Knowledge graph pipelines
What are the strengths of Gremlin?
Database-agnostic-works on many graph engines. Very expressive traversal capabilities. Can handle highly complex multi-hop patterns. Supports distributed analytics (OLAP). Deep control of traversal logic
What are the limitations of Gremlin?
Less beginner-friendly than Cypher. Syntax can become long and verbose. Requires graph theory understanding. Performance varies by underlying graph system
How can I practice Gremlin typing speed?
CodeSpeedTest offers 10+ real Gremlin code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.