Martini Data Model Best Practices
Overview
Following data model best practices helps you create well-structured, maintainable, and efficient data representations in your Martini applications. These practices encompass design principles, naming conventions, structural patterns, and organizational strategies that reduce duplication, improve maintainability, and ensure consistent data handling across your applications.
Applying these best practices becomes critical when building scalable applications where multiple services need to share common data structures or when integrating with databases and external systems that require specific organizational patterns.
What You Will Learn
- How to apply effective naming conventions for Martini data models and properties
- How to design atomic properties that represent single pieces of information
- How to create focused models that represent single business concepts
- How to use model references to eliminate property duplication
- How to avoid circular references and handle self-referencing scenarios
- How to balance database mirroring with API-friendly model design
When To Use This
Apply data model best practices when you need to:
- Remove duplicate properties shared across models
- Build maintainable structures that can evolve safely
- Ensure models work efficiently with databases and APIs
- Organize complex relationships and avoid circular dependencies
- Create shared canonical models used across multiple integrations (see Normalizing Data Models)
Prerequisites
- Martini Designer installed and running
- A Martini Package in the active workspace
- Familiarity with Data Models and their application in Data Mapping and database operations
Best Practices for Canonical Integration Models
If your data models are shared across integrations (for example, a canonical Customer model used by multiple systems), apply these additional guidelines:
- Keep canonical models stable and business-oriented: Prefer additive changes (new fields) over renames/removals. Treat the model as a contract shared across teams and services.
- Preserve source identity: Include fields such as
sourceandlastUpdated, and consider storing a stable cross-system identifier strategy (for example, a canonicalidplus a source-specificexternalId). - Standardize vocabularies: Normalize platform-specific values into a canonical vocabulary (for example, map
enabled/disabledandactive/inactiveinto a single standard). - Separate “source models” from “canonical models”: Keep platform-specific payload models (inputs/outputs) distinct from canonical entities. Avoid mixing platform-specific fields into canonical models.
- Prefer reusable reference models for shared structures: Use dedicated models for repeated structures like
Address,Money, andContactDetailsrather than duplicating fields across entities.
For implementation steps (creating canonical models, mapping, persistence, and APIs), see Normalizing Data Models.
Data Model Naming Conventions
Consistent naming conventions form the foundation of well-designed data models. While multiple standards exist, following consistent patterns makes your models more maintainable and easier for teams to work with.
Recommended Naming Standards
Follow these conventions for consistency across Martini applications:
-
Data Models (in the Navigator view):
- Naming: PascalCase
- Examples:
UserAccount,OrderHistory,CompanyDetails
-
Model Properties:
- Naming: camelCase
- Examples:
firstName,emailAddress,createdDate
-
Models in Services/Workflows:
- Naming: camelCase
- Examples:
userAccount,orderHistory,companyDetails
Choosing Descriptive Model Names
Model names should clearly and concisely describe what the model represents:
Good Examples:
CustomerOrder- clearly represents an order placed by a customerPaymentTransaction- specific to payment-related transactionsUserPreferences- focused on user configuration settings
Avoid Vague Names:
Data- too generic, could represent anythingInfo- doesn't indicate what informationObject- provides no context about purpose
The level of specificity depends on your project scope. Consider whether you have distinct entities that need clear differentiation or related models that fall under similar domains.
Structuring Data with Atomic Properties
Atomic properties represent single pieces of information, making your data easier to filter, search, validate, and manipulate. This principle prevents complex data from being stored in single fields where individual components can't be accessed efficiently.
Creating Atomic Properties
Structure properties so each represents one discrete piece of information:
Avoid: Composite Data
1 2 | |
Better: Atomic Structure
1 2 3 4 | |
Benefits of Atomic Design
Atomic properties provide several operational advantages:
- Filtering: Query by specific address components (all orders from "IL")
- Validation: Apply field-specific rules (zipCode format validation)
- Searching: Enable precise searches (find customers on "Main St")
- Sorting: Order by individual components (sort by state, then city)
- Integration: Map individual fields to external systems
Balancing Atomicity with Use Cases
While atomicity is important, consider your specific requirements:
Display-Oriented Models may benefit from computed properties:
1 2 3 4 | |
Processing-Oriented Models prioritize atomic access:
1 2 3 4 5 | |
Designing Focused Models
Each data model should represent a single business entity or concept. This focused approach makes models easier to understand, maintain, and evolve as your application requirements change.
Single Responsibility Principle for Models
Design models that serve one clear purpose:
Good: Focused Models
1 2 3 4 5 6 7 8 9 10 11 | |
Avoid: Mixed-Purpose Models
1 2 3 4 5 6 7 | |
Note: In some cases, a model may legitimately represent a combination of entities, such as a join table or linking entity used for relationships between two concepts. This is acceptable only when the model truly serves a distinct purpose, not as a shortcut to merge unrelated models. Avoid creating a combined model just to simplify usage; focus on modeling each entity clearly.
Identifying Model Boundaries
Use these guidelines to determine proper model scope:
- Entity Test: Does this model represent one clear business entity?
- Change Test: Do all properties change together, or do some change independently?
- Usage Test: Are all properties needed together in most use cases?
- Ownership Test: Does one business process or domain own all these properties?
If you answer "no" to any of these questions, consider splitting the model into separate, focused models.
Eliminating Duplication with Model References
Model references allow you to share common data structures across multiple models while maintaining a single source of truth. This eliminates duplication and ensures consistency when shared data changes.
Converting Duplicated Properties to References
Transform duplicated properties into referenced models:
Before: Duplicated Properties
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
After: Normalized with References
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
Benefits of Model References
Referenced models provide several advantages:
- Maintainability: Changes to
CompanyModelautomatically apply to all referencing models - Data Integrity: Ensures all models use the same company data structure
- Reusability:
CompanyModelcan be referenced by additional models as needed
Preventing Circular References
Circular references occur when models reference each other in a loop, creating infinite dependency chains that can cause stack overflow errors and make models impossible to evolve safely.
Identifying Circular Reference Problems
Problematic: Direct Circular Reference
1 2 3 4 5 6 7 8 9 | |
This creates an infinite loop: User → Department → User → Department...
Resolving Circular Dependencies
Solution 1: Remove One Direction
1 2 3 4 5 6 7 8 9 | |
Solution 2: Create a Junction Model
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Solution 3: Separate Concerns
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Validation Strategy for Circular References
Before implementing model references, trace the dependency chain:
- List all models that reference each other
- Draw the reference relationships
- Check for any loops in the diagram
- Redesign relationships to eliminate loops
Managing Self-Referencing Models
Self-referencing models are appropriate for hierarchical data where entities can contain or relate to other entities of the same type. Unlike circular references between different models, self-references are intentional and useful for specific data structures.
Appropriate Self-Reference Scenarios
Hierarchical Comments/Replies:
1 2 3 4 5 | |
Organizational Structure:
1 2 3 4 | |
Category Hierarchy:
1 2 3 4 | |
Self-Reference Implementation Guidelines
When working with self-referencing models:
- Handle Root Elements: Account for
nullor missing parent references to support top-level entities. - Control Traversal Depth: Define and enforce maximum depth limits to prevent runaway processing or stack overflows.
- Ensure Clear Exit Conditions: Always define termination rules when traversing hierarchies.
Guideline: Self-referencing models are safe and effective when traversal rules are explicit and bounded.
Database Mirroring Strategies
The database mirroring approach creates models that exactly match your database schema structure. While this provides direct mapping benefits, it also introduces challenges when these models are used in APIs or user interfaces.
Database Mirroring Benefits
Advantages of Direct Schema Matching:
- Direct Mapping from Database Outputs: Because model properties match database table columns, outputs from SQL services and SQL database nodes can be mapped directly to the models without extra transformation.
- Fewer Models to Manage: One model per table reduces the total number of models in the system, simplifying maintenance and oversight.
Database Mirroring Challenges
Problems with Direct Exposure:
1 2 3 4 5 6 7 8 | |
Direct Mirror Problems:
- Security Issues: Internal fields exposed in APIs (
internal_risk_score,password_hash) - User Confusion: Technical fields confuse API consumers (
legacy_migration_flag) - Breaking Changes: Database changes become API breaking changes
- Poor User Experience: Database naming conventions don't match user expectations
Hybrid Mirroring Strategy
Use database-mirrored models for internal operations and create clean API models for external use:
Internal/Persistence Model (Database Mirror):
1 2 3 4 5 6 7 8 | |
External API Model (User-Friendly):
1 2 3 4 5 6 | |
When to Use Each Approach
Use Direct Mirroring When:
- Building internal administrative tools
- Creating data processing workflows
- Security and field exposure aren't concerns
Use Hybrid Strategy When:
- Building public APIs
- Working with legacy database schemas
- Security and data privacy are important
- User experience and clear naming matter
- Database structure may change independently
Adding Model Documentation
Comprehensive documentation helps team members or external developers understand model purposes, relationships, and usage patterns. Martini supports rich documentation directly within model definitions.
Using the Comment Meta-Property
Add documentation to models and properties using the Comment meta-property:
Model-Level Documentation:
1 2 3 4 5 6 7 8 9 | |
Markdown Support for Structured Documentation
The Comment meta-property supports Markdown formatting for complex documentation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
Documentation Best Practices
Recommended Information:
The following details are not required but are often useful for improving clarity, onboarding, and long-term maintainability, especially for shared or complex models.
- Purpose: What the model represents and why it exists
- Usage Context: Where and how the model is used
- Relationships: How it connects to other models
- Validation Rules: Important constraints and business rules
- Examples: Sample data or usage patterns
Keep Documentation Current:
- Update comments when model structure changes
- Review documentation during code reviews
- Include version information for significant changes
- Document breaking changes and migration notes
Use Consistent Style:
- Follow the same documentation format across all models
- Use clear, concise language
- Include both technical and business context
- Link to related documentation when relevant
Versioning and Change Management
Shared data models (especially canonical entities used across integrations and APIs) should be treated as contracts.
- Prefer additive changes: Add new properties rather than renaming or removing existing ones.
- Deprecate intentionally: If a property must be retired, check its Deprecated meta-property (checkbox) and add a comment in the Comment meta-property. Keep deprecated properties available for a defined migration period.
- Avoid silent semantic changes: If the meaning of a property changes, treat that as a breaking change and consider introducing a new property or a versioned model/API.
- Document changes in comments: For significant changes, add a short change note (what changed, why, and the recommended migration path).
Helpful Resources
- Data Model Editor - Complete guide to editing data models
- Data Model Property Types - Understanding different property types and their meta-properties
- Data Model References - Detailed guide managing model references
- Normalizing Data Models - How to design and implement canonical models shared across integrations
- Database Services - Learn about all database services available
- Database Nodes - Explore all database nodes in workflows
- Community Q&A: Martini Community
Have a Question? Post or search it here.