1. Graph Data Model
The graph data model centers on nodes and edges and is used to represent entities and relationships.
Example:
(Alice) -[:FOLLOWS]-> (Bob)
Graph models aren't used only by graph databases. Many forms of knowledge representation, social networks, recommender systems, and path analysis fundamentally rely on graph structures.
1.1 Core Advantages of the Graph Model
| Capability | Description |
|---|---|
| Expressing complex relationships | Naturally suited to complex data structures such as n-to-n relationships, multi-hop paths, and hierarchical containment |
| Flexible schema (schema-less) | Entity types and relationship types can be extended at any time |
| More stable performance as relationships grow | Multi-hop queries are usually more efficient than JOINs in relational databases |
| Supports recursive queries | e.g., org structures, geographic containment (within), path discovery |
1.2 Differences from the Relational Data Model
The relational model emphasizes tables + foreign keys and is suited to business data with a clear structure.
The graph model emphasizes relationships and connectivity and is suited to traversal, search, recommendation, and provenance problems.
Graph models are used extensively in industry for:
Knowledge graphs
Risk-control path tracing
Network topology analysis
Social relationship graphs
Supply chain dependency graphs
Event causality chains
2. Event Sourcing
Event sourcing is a pattern that stores data as a sequence of events rather than as the current state.
Traditional systems store the current state:
Event sourcing stores change events:
Deposit 100
Withdraw 20
Deposit 40
The current state is derived by replaying the events.
2.1 Why Use Event Sourcing?
| Requirement | Advantage of event sourcing |
|---|---|
| Auditability | Every state change is recorded |
| System recovery | Any point-in-time state can be recovered by replaying events |
| Traceable evolution of business logic | The path by which data formed is clearly visible |
| Built-in support for time travel | Restore past states and compare differences |
| Natural fit for event-driven architecture | Events can drive updates, notifications, and other actions in other microservices |
2.2 Event Storage Format
Events usually contain:
Different systems can store events in:
Logs (Kafka)
EventStore
Relational databases (EventStream partitioned by aggregate)
Document databases
3. CQRS (Command Query Responsibility Segregation)
CQRS is an architectural pattern that separates commands from queries.
Core idea:
Modifying data and reading data should use different models because the requirements are completely different.
3.1 Why Separate Them?
| Command (write) | Query (read) |
|---|---|
| Strong consistency | High performance, high availability |
| Complex validation | Can cache, can use materialized views |
| Updates limited data | Reads data across aggregates and multiple dimensions |
| Strong transactional behavior | Can use async and eventual consistency |
3.2 Relationship Between CQRS and Event Sourcing
The two are often used together:
Write model (command model)
- Produces events
Events are broadcast (event bus)
Read model (query model)
- Subscribes to events
- Updates its own projection / view
This structure is naturally suited to:
Systems with high read/write separation
Reporting systems
Activity logs
Businesses with complex read views (such as e-commerce order status summaries)
4. Model Differences Between DataFrames, Matrices, and Arrays
DataFrames, matrices, and arrays are three common structures in data systems, each with a different focus.
4.1 Arrays
One-dimensional or multidimensional, with elements of the same type.
Example:
[1, 2, 3]
Or multidimensional:
[[1,2], [3,4]]
Suited to numerical computing, image matrices, and vector spaces.
4.2 Matrices
Essentially two-dimensional arrays, but with mathematical meaning: linear algebra operations.
- Emphasize rows and columns (shape)
- Support matrix multiplication, eigendecomposition, transposition, and more
A matrix can be seen as a semantic subset of an array.
4.3 DataFrames
A table-like structure:
- Columns can have different types (strings, floats, dates)
- Each column has a label, and each row has an index
- Commonly used for data analysis (Pandas, R DataFrame)
Example:
| name | age | score |
|---|---|---|
| Alice | 25 | 88 |
| Bob | 30 | 92 |
Suited to:
- Statistical analysis
- Data cleaning
- Processing structured data with multiple fields
4.4 Comparison of the Three
| Feature | Array | Matrix | DataFrame |
|---|---|---|---|
| Dimensionality | Any | Two-dimensional | Two-dimensional (with column names) |
| Type uniformity | Required | Uniform | Not required |
| Focus of operations | Numerical computing | Linear algebra operations | Analysis / ETL |
| Application areas | AI, image processing | Inside machine learning algorithms | Data analysis, BI |
5. Integrated View: How Data Models and Architectural Patterns Relate
Graph data models, event sourcing, CQRS, and DataFrames/matrices/arrays actually sit at different layers of the data processing chain:
📌 Data representation layer (structure)
- Arrays / matrices: numerical computation
- DataFrames: analytical data
- Graph data models: the data form with the strongest relationships and connectivity
📌 Data behavior layer (how data changes)
- Event sourcing: a record of data evolution
- CQRS: structural separation of read and write requirements
📌 Architecture layer (how systems organize data)
In complex systems, these often appear in combination:
- Graph model + event sourcing
→ Build knowledge graphs from events (event streams form relationship graphs) - CQRS + event sourcing
→ A common microservices pattern: the write side produces events, and the read side builds multiple views (table views, graph views) - DataFrames / arrays / matrices
→ Secondary processing of events (analysis, machine learning)
📌 Summary
The core idea of this summary is:
Graph models are stronger at expressing relationships, event sourcing records where state comes from, CQRS optimizes read/write logic, and DataFrames/matrices/arrays are the foundation of the data analysis and computation layer.
In modern system architectures, they often jointly form:
Data collection (events)
Data relationship construction (graphs)
Data querying (CQRS read models)
Data analysis (DataFrame / Matrix / Array)
Machine learning and inference