Introduction to Data Modeling
Embeddable uses a semantic layer to define and manage your data.
What is a Semantic Layer?
A semantic layer is an abstraction layer that sits between raw data in databases and your analytics, defining data in clear, consistent terms that users understand.
It's especially beneficial for customer-facing analytics because it ensures:
- Consistency: Unified metrics and definitions across all dashboards.
- Maintainability: Centralized business logic, avoiding code duplication.
- Performance: Query optimization and reduced load on databases.
Under the hood, Embeddable uses Cube (opens in a new tab) as its semantic layer. This means you can define, manage, and transform data in a standard format (access Cube's docs here (opens in a new tab)).
Data Models
Data models are the building blocks that power the semantic layer.
If you think of the semantic layer as the high-level framework for defining and interpreting data across your organization, data models spell out the actual fields, relationships, and aggregations.
A Basic Example
Suppose you have a customers
table:
id | signed_up_at | country | |
---|---|---|---|
1 | strahar0@... | 2023-09-04 | United States |
2 | smcpeake1@... | 2021-09-06 | Iceland |
3 | jeffrey_b@... | 2021-09-06 | Canada |
To model this in Embeddable you might create a file like so inside your repo:
# src/models/customers.cube.yml
cubes:
- name: customers
title: "My Customers"
sql: >
select *
from public.customers
dimensions:
- name: country
title: "Country of origin"
sql: country
type: string
- name: signed_up_date
title: "Signed up date"
sql: signed_up_at
type: time
measures:
- name: count
type: count
title: "# of Customers"
name
: A unique identifier (no spaces or special characters).title
(optional): A friendly name that appears in the UI.sql_table
: Points to the actual table or view in your database.sql
: Rather than pointing to a table / view, you can write SQL (matching your own database's dialect).dimensions
: Fields to filter or group by (think columns or derived fields).measures
: Aggregations (count, sum, avg, etc.).
Using your data models
Once you've defined your data models, push them to your Embeddable workspace to make them available in the no-code dashboard builder.
You'll be able to use your models to populate data for charts and other components e.g. a pie chart that shows a count of customers grouped by country. You don't need to worry about writing SQL - it gets generated behind the scenes automatically based on your models.
Importantly, Embeddable does not take a copy of your database. Instead, it runs the SQL generated from your models against your database, and securely retrieves only the returned results. To improve performance and also protect your database from too much load, you can configure caching.
Getting started
Here are some practical tips to help you design clear and manageable data models, especially when starting with a large database.
-
Start Small: Identify just one or two key tables or entities from your database that support your main analytics use cases, and create simple models for those.
-
Add Complexity Gradually: Once you have the basics working, expand your models with additional tables or fields as new insights are needed.
-
Keep Models Focused: Keep each model mapped to a clear, logical part of your database to avoid confusion and make maintenance easier.
-
Use Clear Naming: Give each model and field descriptive names that reflect its purpose. This helps everyone on your team understand the data at a glance.
-
Document as You Go: Briefly note what each model represents and how it’s used, so new team members or future you can jump in without guesswork.