Skip to content

Understand the data model

This page explains the graph data model used in the example application. You will learn how vertices, edges, and properties work together to represent financial transactions.

Property graph model

Aerospike Graph uses the property graph model, which consists of three core components:

  • Vertices represent entities (users, accounts)
  • Edges represent relationships between entities (ownership, transactions)
  • Properties store attributes on both vertices and edges

This model excels at representing connected data where relationships are as important as the entities themselves.

Vertices: Users and accounts

The example creates two types of vertices: User vertices and Account vertices.

User vertices

User vertices represent people who own accounts. Each user has three properties:

final Vertex user1 = g.addV("User").property("userId", "U1").property("name", "Alice").property("age", 30).next();
final Vertex user2 = g.addV("User").property("userId", "U2").property("name", "Bob").property("age", 35).next();
final Vertex user3 = g.addV("User").property("userId", "U3").property("name", "Charlie").property("age", 25).next();
final Vertex user4 = g.addV("User").property("userId", "U4").property("name", "Diana").property("age", 28).next();
final Vertex user5 = g.addV("User").property("userId", "U5").property("name", "Eve").property("age", 32).next();

Each addV() step creates a new vertex with the label “User”. The property() steps attach attributes to the vertex. The next() method executes the traversal and returns the created vertex object.

Key properties:

  • userId: Unique identifier (U1, U2, etc.)
  • name: User’s display name
  • age: User’s age in years

Account vertices

Account vertices represent bank accounts. Each account has two properties:

final Vertex account1 = g.addV("Account").property("accountId", "A1").property("balance", 5000).next();
final Vertex account2 = g.addV("Account").property("accountId", "A2").property("balance", 3000).next();
final Vertex account3 = g.addV("Account").property("accountId", "A3").property("balance", 4000).next();
final Vertex account4 = g.addV("Account").property("accountId", "A4").property("balance", 2000).next();
final Vertex account5 = g.addV("Account").property("accountId", "A5").property("balance", 6000).next();

Key properties:

  • accountId: Unique identifier (A1, A2, etc.)
  • balance: Current account balance

Edges: Ownership and transactions

Edges connect vertices to represent relationships. The example uses two types of edges.

Ownership edges

Ownership edges link users to their accounts. These edges use the from() and to() methods to specify the source and target vertices:

g.addE("owns").from(user1).to(account1).property("since", "2020").iterate();
g.addE("owns").from(user2).to(account2).property("since", "2021").iterate();
g.addE("owns").from(user3).to(account3).property("since", "2022").iterate();
g.addE("owns").from(user4).to(account4).property("since", "2023").iterate();
g.addE("owns").from(user5).to(account5).property("since", "2024").iterate();

The addE() step creates an edge with the label “owns”. The edge has one property:

  • since: The year the user opened the account

The iterate() method executes the traversal without returning a result. Use iterate() when you don’t need to capture the created edge object.

Transaction edges

Transaction edges represent money transfers between accounts:

g.addE("Transaction")
.from(account1).to(account2)
.property("transactionId", "T1")
.property("amount", 200)
.property("type", "debit")
.property("timestamp", convertTimestampToLong("2023-01-15"))
.iterate();
g.addE("Transaction")
.from(account2).to(account1)
.property("transactionId", "T2")
.property("amount", 150)
.property("type", "credit")
.property("timestamp", convertTimestampToLong("2023-01-16"))
.iterate();

Each transaction edge has four properties:

  • transactionId: Unique identifier (T1, T2, etc.)
  • amount: Transfer amount in currency units
  • type: Transaction type (debit or credit)
  • timestamp: When the transaction occurred (stored as a long integer)

The example then generates 50 additional random transactions by sampling pairs of accounts and creating transaction edges between them:

for (int i = 1; i <= 50; i++) {
final Vertex fromAccount = g.V().hasLabel("Account").sample(1).next();
final Vertex toAccount = g.V().hasLabel("Account").sample(1).next();
final int amount = random.nextInt(1000) + 1;
final String transactionId = "T" + i;
final String type = random.nextBoolean() ? "debit" : "credit";
final String timestamp = String.format("2025-%02d-%02d", random.nextInt(11) + 1, random.nextInt(28) + 1);
g.addE("Transaction")
.from(fromAccount).to(toAccount)
.property("transactionId", transactionId)
.property("amount", amount)
.property("type", type)
.property("timestamp", convertTimestampToLong(timestamp))
.iterate();
}

Graph structure

The resulting graph structure looks like this:

User (Alice) --owns--> Account (A1) --Transaction--> Account (A2) <--owns-- User (Bob)
User (Bob) --owns--> Account (A2) --Transaction--> Account (A1) <--owns-- User (Alice)

Each user owns exactly one account, but accounts can have many incoming and outgoing transaction edges. This structure lets you efficiently traverse from users to their transactions and from transactions back to the users involved.

Graph traversal source

All vertex and edge creation operations start with the graph traversal source g:

private static final String HOST = "localhost";
private static final int PORT = 8182;
private static final Cluster.Builder BUILDER = Cluster.build()
.addContactPoint(HOST)
.port(PORT)
.enableSsl(false);
final Cluster cluster = BUILDER.create();
final GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster));

The g object provides methods for creating and querying the graph. It maintains a connection to AGS through the Gremlin Server protocol, sending your Gremlin steps to the server for execution.

Key concepts

  • Vertices are created with addV() and represent entities
  • Edges are created with addE() and represent relationships
  • Properties are attached with property() and store attributes
  • Labels (like “User” or “Transaction”) categorize vertices and edges
  • Direction matters: edges point from a source vertex to a target vertex
  • next() executes a traversal and returns a single result
  • iterate() executes a traversal without returning results
  • The Java driver uses strongly typed objects like Vertex and GraphTraversalSource
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?