---
title: "Understand the data model"
description: "Learn the Aerospike Graph property model using vertices, edges, and properties in a transaction example."
---

# Understand the data model

> For the complete documentation index see: [llms.txt](https://aerospike.com/docs/llms.txt)
> 
> All documentation pages available in markdown.

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:

```python
user1 = g.add_v("User").property("userId", "U1").property("name", "Alice").property("age", 30).next()

user2 = g.add_v("User").property("userId", "U2").property("name", "Bob").property("age", 35).next()

user3 = g.add_v("User").property("userId", "U3").property("name", "Charlie").property("age", 25).next()

user4 = g.add_v("User").property("userId", "U4").property("name", "Diana").property("age", 28).next()

user5 = g.add_v("User").property("userId", "U5").property("name", "Eve").property("age", 32).next()
```

Each `add_v()` 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:

```python
account1 = g.add_v("Account").property("accountId", "A1").property("balance", 5000).next()

account2 = g.add_v("Account").property("accountId", "A2").property("balance", 3000).next()

account3 = g.add_v("Account").property("accountId", "A3").property("balance", 4000).next()

account4 = g.add_v("Account").property("accountId", "A4").property("balance", 2000).next()

account5 = g.add_v("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:

```python
g.add_e("owns").from_(user1).to(account1).property("since", "2020").iterate()

g.add_e("owns").from_(user2).to(account2).property("since", "2021").iterate()

g.add_e("owns").from_(user3).to(account3).property("since", "2022").iterate()

g.add_e("owns").from_(user4).to(account4).property("since", "2023").iterate()

g.add_e("owns").from_(user5).to(account5).property("since", "2024").iterate()
```

The `add_e()` 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:

```python
g.add_e("Transaction") \

    .from_(account1).to(account2) \

    .property("transactionId", "T1") \

    .property("amount", 200) \

    .property("type", "debit") \

    .property("timestamp", convert_timestamp_to_long("2023-01-15")) \

    .iterate()

g.add_e("Transaction") \

    .from_(account2).to(account1) \

    .property("transactionId", "T2") \

    .property("amount", 150) \

    .property("type", "credit") \

    .property("timestamp", convert_timestamp_to_long("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.

## Graph structure

The resulting graph structure looks like this:

```plaintext
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`:

```python
cluster = DriverRemoteConnection("ws://{host}:{port}/gremlin".format(host=HOST, port=PORT), "g")

g = traversal().with_remote(cluster)
```

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

## Key concepts

-   **Vertices** are created with `add_v()` and represent entities
-   **Edges** are created with `add_e()` 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

::: undefined
-   I understand how vertices represent entities in the graph.
-   I understand how edges represent relationships between entities.
-   I understand how properties store attributes on vertices and edges.
:::

[Previous  
Run the example](https://aerospike.com/docs/graph/graph-and-python-basics/step/1/part/1/run-example) [Next  
Review queries](https://aerospike.com/docs/graph/graph-and-python-basics/step/2/part/1/review-queries)