Monday, 13 April 2026

Getting Started with TinkerGraph in the Gremlin Console

  

TinkerGraph is the reference, in-memory graph implementation provided by Apache TinkerPop. It is lightweight, fast to start, and requires no external dependencies, making it ideal for learning Gremlin, experimenting with traversals, and prototyping graph based solutions.

 

This post explains how TinkerGraph is enabled and used within the Gremlin Console, how to initialize a graph instance, and how to prepare the traversal infrastructure required to execute Gremlin queries. Along the way, it establishes conventions that will be used consistently throughout this tutorial series.

 

1. TinkerGraph Support in the Gremlin Console

When the Gremlin Console is launched, support for TinkerGraph is typically enabled by default. Starting the console using the gremlin.sh script produces output similar to the following.

$ gremlin.sh

         \,,,/
         (o o)
-----oOOo-(3)-oOOo-----
plugin activated: tinkerpop.server
plugin activated: tinkerpop.utilities
plugin activated: tinkerpop.tinkergraph
gremlin>

The presence of plugin activated: tinkerpop.tinkergraph confirms that the TinkerGraph plugin is already available in the console session.

 

Enabling the TinkerGraph Plugin Manually

In rare cases such as after a customized console setup or plugin changes, the TinkerGraph plugin may not be active. If this happens, it can be enabled explicitly using the following command:

:plugin use tinkerpop.tinkergraph

Once executed, the console confirms activation.

gremlin> :plugin use tinkerpop.tinkergraph
==>tinkerpop.tinkergraph activated

After enabling the plugin manually, it is recommended to close and restart the Gremlin Console. Restarting ensures that all classes and bindings associated with TinkerGraph are properly loaded and available for use.

 

2. Creating a TinkerGraph Instance

With the plugin enabled and the console restarted, a new in-memory graph instance can be created directly from the console.

graph = TinkerGraph.open()

gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]

   

This call creates an empty TinkerGraph instance using default configuration settings. At this stage:

 

·      The graph resides entirely in memory.

·      All data is lost when the console session ends unless explicitly persisted.

·      The graph is suitable for interactive exploration and learning.

 

In more advanced scenarios, parameters can be passed to the open() method to control aspects such as persistence, indexing, or custom configuration. These options will be explored in later posts.

 

3. Establishing a Graph Traversal Source

Creating a graph instance alone is not sufficient to run Gremlin queries. Gremlin traversals are executed through a graph traversal source, which acts as the entry point for all traversal operations. A traversal source is created as follows:

 

g = graph.traversal()

gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]

The variable g now represents a traversal source bound to the graph instance. All Gremlin queries begin from this object. Conceptually:

 

graph represents the data structure and storage.

g represents the query context and execution engine for traversals.

 

4. Creating a Simple Graph

With the graph and traversal source in place, it is now possible to create a simple graph and run basic traversals.

 

4.1 Adding Vertices

The following commands add two vertices representing people:

 

v1 = g.addV('person').property('name', 'Alice').next()
v2 = g.addV('person').property('name', 'Bob').next()

   

Each vertex is labeled person and has a name property.

 

gremlin> v1 = g.addV('person').property('name', 'Alice').next()
==>v[0]
gremlin> v2 = g.addV('person').property('name', 'Bob').next()
==>v[2]
gremlin> 
gremlin> graph
==>tinkergraph[vertices:2 edges:0]
gremlin> 
gremlin> g
==>graphtraversalsource[tinkergraph[vertices:2 edges:0], standard]

4.2 Adding an Edge

Next, an edge is created to represent a relationship between Alice and Bob.

g.V(v1).addE('knows').to(v2).next()

gremlin> g.V(v1).addE('knows').to(v2).next()
==>e[4][0-knows->2]

This edge indicates that Alice “knows” Bob.

 

4.3 Running Basic Traversals

Once the graph is populated, simple traversals can be executed to explore it.

 

Retrieve all vertices:

g.V()

 

gremlin> g.V()
==>v[0]
==>v[2]

   

Retrieve all person names:

 

g.V().values('name')

gremlin> g.V().values('name')
==>Alice
==>Bob

Find who Alice knows:

g.V().has('name', 'Alice').out('knows').values('name')

 

gremlin> g.V().has('name', 'Alice').out('knows').values('name')
==>Bob

   

These examples illustrate a fundamental idea in Gremlin, traversals describe how to walk the graph, step by step, rather than declaring what data to fetch in a purely declarative manner.

 

Understanding this flow early makes it significantly easier to reason about more advanced topics such as schema design, traversal optimization, graph computer usage, and production deployments.

 

Previous                                                    Next                                                    Home

TinkerGraph: An In-Memory Reference Implementation for Learning and Exploration

Every Apache TinkerPop distribution includes a reference implementation of an in-memory graph called TinkerGraph. TinkerGraph is intentionally simple, lightweight, and easy to run, making it an ideal starting point for anyone learning Gremlin or experimenting with graph concepts.

 

Because it runs entirely in memory and requires no external services, TinkerGraph can be started on a laptop or desktop computer in seconds. This low barrier to entry makes it especially valuable for:

 

·      Learning Gremlin traversal syntax

·      Prototyping graph models

·      Writing and validating example traversals

·      Testing ideas before moving to a distributed or persistent graph system

 

In practice, TinkerGraph often serves as a sandbox, a safe, fast environment where developers can focus on understanding graph semantics rather than infrastructure.

 

TinkerPop Feature Model and Capability Discovery

Apache TinkerPop 3 defines a formal feature model that describes what capabilities a graph system may or may not support. These features span multiple dimensions, including:

 

·      Graph-level behavior (transactions, persistence, threading)

·      Vertex and edge creation and removal

·      Identifier types and constraints

·      Property data types and mutability

·      Support for advanced concepts such as meta-properties

 

Not all features are mandatory. Some are required by the TinkerPop specification, while others are optional and implementation specific. This design allows a wide range of graph systems from simple in-memory graphs to large-scale distributed databases to integrate with TinkerPop while accurately advertising their capabilities.

 

Once a Graph instance has been created, its supported features can be inspected programmatically using the features() API.

graph = TinkerGraph.open()
graph.features()

When executed above statements in the Gremlin Console, this command produces a structured report detailing which features are enabled.

gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> 
gremlin> graph.features()
==>FEATURES
> GraphFeatures
>-- Computer: true
>-- IoRead: true
>-- IoWrite: true
>-- ConcurrentAccess: false
>-- ThreadedTransactions: false
>-- Persistence: true
>-- Transactions: false
>-- OrderabilitySemantics: true
>-- ServiceCall: true
> VariableFeatures
>-- Variables: true
>-- ByteValues: true
>-- LongValues: true
>-- MapValues: true
>-- BooleanValues: true
>-- DoubleValues: true
>-- FloatArrayValues: true
>-- MixedListValues: true
>-- SerializableValues: true
>-- StringValues: true
>-- UniformListValues: true
>-- ByteArrayValues: true
>-- BooleanArrayValues: true
>-- DoubleArrayValues: true
>-- IntegerValues: true
>-- FloatValues: true
>-- StringArrayValues: true
>-- IntegerArrayValues: true
>-- LongArrayValues: true
> VertexFeatures
>-- Upsert: false
>-- MetaProperties: true
>-- AddVertices: true
>-- RemoveVertices: true
>-- DuplicateMultiProperties: true
>-- MultiProperties: true
>-- NumericIds: true
>-- StringIds: true
>-- UuidIds: true
>-- CustomIds: false
>-- AnyIds: true
>-- NullPropertyValues: false
>-- UserSuppliedIds: true
>-- AddProperty: true
>-- RemoveProperty: true
> VertexPropertyFeatures
>-- NumericIds: true
>-- StringIds: true
>-- UuidIds: true
>-- CustomIds: false
>-- AnyIds: true
>-- NullPropertyValues: false
>-- UserSuppliedIds: true
>-- RemoveProperty: true
>-- Properties: true
>-- ByteValues: true
>-- LongValues: true
>-- MapValues: true
>-- BooleanValues: true
>-- DoubleValues: true
>-- FloatArrayValues: true
>-- MixedListValues: true
>-- SerializableValues: true
>-- StringValues: true
>-- UniformListValues: true
>-- ByteArrayValues: true
>-- BooleanArrayValues: true
>-- DoubleArrayValues: true
>-- IntegerValues: true
>-- FloatValues: true
>-- StringArrayValues: true
>-- IntegerArrayValues: true
>-- LongArrayValues: true
> EdgeFeatures
>-- AddEdges: true
>-- Upsert: false
>-- RemoveEdges: true
>-- NumericIds: true
>-- StringIds: true
>-- UuidIds: true
>-- CustomIds: false
>-- AnyIds: true
>-- NullPropertyValues: false
>-- UserSuppliedIds: true
>-- AddProperty: true
>-- RemoveProperty: true
> EdgePropertyFeatures
>-- Properties: true
>-- ByteValues: true
>-- LongValues: true
>-- MapValues: true
>-- BooleanValues: true
>-- DoubleValues: true
>-- FloatArrayValues: true
>-- MixedListValues: true
>-- SerializableValues: true
>-- StringValues: true
>-- UniformListValues: true
>-- ByteArrayValues: true
>-- BooleanArrayValues: true
>-- DoubleArrayValues: true
>-- IntegerValues: true
>-- FloatValues: true
>-- StringArrayValues: true
>-- IntegerArrayValues: true
>-- LongArrayValues: true

Interpreting graph.features()

The output of graph.features() is organized into logical categories. Each category exposes fine grained capability flags that describe exactly how the graph behaves.

 

At a high level, the output includes:

 

GraphFeatures: Describe graph-wide capabilities such as:

·      Persistence support

·      Transaction semantics

·      Threading and concurrent access

·      GraphComputer availability

 

VariableFeatures: Indicate whether graph variables are supported and which data types may be stored.

 

VertexFeatures and EdgeFeatures: Specify whether vertices and edges can be added, removed, or updated, along with supported identifier types and property behavior.

 

VertexPropertyFeatures and EdgePropertyFeatures: Detail property level constraints, including:

·      Supported value types

·      Whether null values are allowed

·      Whether properties themselves may have properties (meta-properties)

 

For example, TinkerGraph reports support for multiple identifier types (numeric, string, UUID), multi-properties on vertices, and a wide range of property value types. At the same time, it explicitly reports the absence of transactional guarantees.

 

This explicit feature declaration is critical for writing portable Gremlin code. Traversals that rely on unsupported features may work in one graph system but fail in another. The features() API provides a reliable way to reason about those differences.

 

Strengths and Intended Use Cases

TinkerGraph excels in scenarios where simplicity and speed matter more than scale or durability. Common use cases include:

 

·      Learning and teaching Gremlin: Its predictable behavior and instant startup make it ideal for tutorials, workshops, and books.

·      Local experimentation: Developers can iterate quickly without provisioning servers or configuring storage backends.

·      Subgraph extraction and analysis: A portion of a larger graph can be exported, loaded into TinkerGraph, and explored locally. This is especially useful for debugging complex traversals or analyzing specific regions of a graph.

·      Static graph exploration: TinkerGraph is often used with graphs that do not change during execution, such as reference datasets or snapshots.

 

Although primarily positioned as a development and learning tool, TinkerGraph can also be used in production environments when the dataset comfortably fits in memory and advanced features are not required.

 

Mutability and Programming Language Integration

Despite its frequent use with static graphs, TinkerGraph is fully mutable. When embedded in a programming language such as Java, applications may freely add, update, and remove vertices, edges, and properties.

 

This makes TinkerGraph useful not only for querying graphs but also for testing mutation logic and traversal side effects. However, all mutations occur in memory and are subject to the limitations discussed next.

 

Limitations Compared to Production Graph Systems

TinkerGraph deliberately omits several advanced features commonly found in production grade graph databases such as JanusGraph. Notable limitations include:

 

·      No transactional support

·      No external or secondary indexing

·      Limited concurrency guarantees

·      No distributed execution model

 

These omissions simplify the implementation and keep TinkerGraph lightweight, but they also mean it is not a drop-in replacement for scalable, persistent graph systems.

 

As a mental model, TinkerGraph can be viewed as a reference implementation rather than a full database engine, it demonstrates how TinkerPop concepts fit together without attempting to solve hard problems such as durability, scalability, or concurrent access.

 

Identifier Handling and Graph Imports

One important practical detail is TinkerGraph’s handling of identifiers during graph imports. When loading graph files such as those in GraphML format, it honors explicitly defined vertex and edge identifiers and preserves those IDs.

 

This behavior is especially useful when:

·      Working with preexisting datasets

·      Maintaining identifier consistency across environments

·      Comparing behavior between different graph systems

 

By respecting supplied identifiers, TinkerGraph ensures that imported graphs retain their structural and semantic integrity.

 

In summary, TinkerGraph plays a foundational role within the Apache TinkerPop ecosystem. It is simple by design, transparent in its capabilities, and highly accessible. While it lacks the advanced features required for large-scale or mission-critical deployments, it remains an indispensable tool for learning, experimentation, and precise reasoning about Gremlin traversals and graph behavior.

  

 

Previous                                                    Next                                                    Home

Recording Gremlin Console Sessions to a File

During interactive exploration, debugging, or teaching, it is often useful to preserve a complete record of a Gremlin Console session. Recording allows commands and their corresponding results to be written to a file as they are executed. This is particularly valuable for:

 

·      Auditing or reviewing exploratory queries

·      Sharing reproducible examples with colleagues or students

·      Capturing output for documentation or reports

·      Retaining evidence of graph state during troubleshooting

 

The Gremlin Console provides built-in support for this workflow through the :record command.

 

The :record Command

Session recording is controlled entirely from within the console using the :record command. Recording can be started and stopped explicitly, allowing precise control over which portions of a session are captured.

 

The general form is:

 

·      :record start <file-path> - begin recording all subsequent commands and output

·      :record stop — end the recording and close the file

 

While recording is active, every Gremlin command entered and every result produced by the console is written to the specified file.

 

The following example demonstrates how to record a short Gremlin Console session to a file named mylog.txt.

 

Execute following statement from Gremlin console.

:record start /Users/Shared/mylog.txt

gremlin> :record start /Users/Shared/mylog.txt
Recording session to: "/Users/Shared/mylog.txt"
==>/Users/Shared/mylog.txt

   

From this point onward, all commands and results are captured until recording is stopped.

 

Let's create a Graph and Graph traversal instance by executing below statements.

 

graph = TinkerFactory.createModern()
g = traversal().with(graph)

gremlin> graph = TinkerFactory.createModern()
==>tinkergraph[vertices:6 edges:6]
gremlin> g = traversal().with(graph)
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]

The traversal source, typically named g, serves as the entry point for all Gremlin queries against the graph.

 

With recording enabled, traversals and their results are written to the log file automatically.

 

The following traversal counts the total number of vertices in the graph:

gremlin> g.V().count().next()
==>6

   

Here, V() selects all vertices, count() computes the total, and next() retrieves the scalar result from the traversal. The next traversal retrieves a detailed view of each vertex, including identifiers, labels, and properties:

 

gremlin> g.V().valueMap(true)
==>[id:1,label:person,name:[marko],age:[29]]
==>[id:2,label:person,name:[vadas],age:[27]]
==>[id:3,label:software,name:[lop],lang:[java]]
==>[id:4,label:person,name:[josh],age:[32]]
==>[id:5,label:software,name:[ripple],lang:[java]]
==>[id:6,label:person,name:[peter],age:[35]]

The valueMap(true) step includes both element identifiers and labels, making it useful for inspection and debugging. A detailed explanation of Gremlin traversals and steps follows in subsequent sections of this tutorial.

 

Stopping the Recording

Once the relevant portion of the session has been captured, recording is stopped explicitly by exeucting below command.

:record stop

gremlin> :record stop
Recording stopped; session saved as: "/Users/Shared/mylog.txt" (435 bytes)
==>/Users/Shared/mylog.txt

At this point, the file is closed and no further console activity is written to it.

 

Inspecting the Recorded Output

Opening the generated mylog.txt file reveals a structured, chronological record of the session.

$cat /Users/Shared/mylog.txt 
// OPENED: Fri Jan 09 14:14:12 IST 2026
// RESULT: /Users/Shared/mylog.txt
graph = TinkerFactory.createModern()
// RESULT: tinkergraph[vertices:6 edges:6]
g = traversal().with(graph)
// RESULT: graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
g.V().count().next()
// RESULT: 6
g.V().valueMap(true)
// RESULT: [TinkerGraphStep(vertex,[]), PropertyMapStep(null,value)]
:record stop
// CLOSED: Fri Jan 09 14:17:41 IST 2026

Each command is followed by a // RESULT: line containing the console’s response. The file also includes timestamps marking when recording began and ended, providing useful contextual information for later review.

 

When using session recording, keep the following points in mind:

 

·      Recording captures both commands and results, not just output

·      Absolute or relative file paths may be used, depending on the environment

·      Sensitive data should be handled carefully when sharing recorded files

·      Recorded sessions can serve as executable documentation, but may require minor cleanup for presentation purposes

 

Used thoughtfully, the :record command transforms the Gremlin Console into a powerful tool for reproducibility, learning, and collaboration.

 


 

Previous                                                    Next                                                    Home