SlideShare a Scribd company logo
1 of 45
Download to read offline
Materialized Views
Carl Yeksigian
What are Materialized Views?
• Two copies of the data using different partitioning and placed
on different replicas
• Automated, server-side denormalization of data
• Native Cassandra read performance
• Write penalty, but acceptable performance
Basic Rules of Data Modeling, Refresher
• Best practice: Denormalization
• Start by understanding the queries you need
• Create a table for each query
Why is Denormalization Hard?
• Implemented by every application
• No guarantees on performance or consistency
• Updates to existing rows require cleanup, read-before-write
Denormalization Example: User Playlists
Queries
• All Songs for a given
playlist
• Track Users who like
the same Artist
• Find most recently
played song
Denormalization in Practice
CREATE TABLE playlists
(user_name text,
playlist_name text,
song_id text,
artist_name text,
last_played timestamp)
SELECT song_id
FROM playlists
WHERE user_name=‘carl’
AND playlist_name=‘jams’
SELECT COUNT(song_id)
FROM playlists
WHERE artist_name=‘Weezer’
SELECT last_played, song_id
FROM playlists
WHERE user_name=‘carl’
AND playlist_name=‘jams’
ORDER BY last_played DESC
Denormalization in Practice
CREATE TABLE playlists
(user_name text,
playlist_name text,
song_id text,
artist_name text,
last_played timestamp,
PRIMARY KEY (user_name, playlist_name, song_id))
CREATE TABLE artists_to_playlists
(artist_name text,
user_name text,
playlist_name text,
song_id text,
PRIMARY KEY (artist_name, user_name, playlist_name, song_id))
Denormalization in Practice
CREATE TABLE last_played
(user_name text,
playlist_name text,
last_played timestamp,
song_id text,
PRIMARY KEY (user_name, playlist_name, last_played, song_id))
CLUSTERING ORDER BY (last_played DESC)
Denormalization in Practice: Inserts
BEGIN BATCH
INSERT INTO playlists
(user_name, playlist_name, song_id, artist_name, last_played)
VALUES (‘carl’, ‘jams’, ‘Undone’, ‘Weezer’, ‘2015-09-24 09:00’);
INSERT INTO artists_by_playlist
(artist_name, user_name, playlist_name, song_id)
VALUES (‘Weezer’, ‘carl’, ‘jams’, ‘Undone’);
INSERT INTO last_played
(user_name, playlist_name, last_played, song_id)
VALUES (‘carl’, ‘jams’, ‘Undone’, ‘2015-09-24 09:00’);
APPLY BATCH;
Denormalization in Concept: Updates
UPDATE playlists
SET last_updated=now()
WHERE user_name=‘carl’
AND playlist_name=‘jams’
AND song_id=‘Undone’
DELETE FROM playlists
WHERE user=‘carl’
Manual Denormalization with updates
Client Batchlog
Base Table
View Table
Coordinator
Manual Denormalization with updates
Client Batchlog
Base Table
View Table
Coordinator
Query Existing Data
Manual Denormalization with updates
Client Batchlog
Base Table
View Table
Coordinator
Query Existing Data
Query Existing Data
Manual Denormalization with updates
Client Batchlog
Base Table
View Table
Coordinator
Query Existing Data
Query Existing Data Return Existing Data
Return Existing Data
Manual Denormalization with updates
Client Batchlog
Base Table
View Table
Coordinator
Write New Values
Manual Denormalization with updates
Client Batchlog
Base Table
View Table
Coordinator
Write New Values Write New Values
Manual Denormalization with updates
Client Batchlog
View Table
Coordinator
Write New Values Write New Values
Base Table
Write New Values
Manual Denormalization with updates
Manual Denormalization Limitations
• Updates need to keep view in sync, including tombstoning
previous values
• How to keep the view and base in sync on failure?
• Contentious updates can potentially cause extra values
• Your application doesn’t always know what is a update or an
insert (i.e. upsert)
Manual Denormalization: Contentious Updates
Client 1
Cassandra
Client 2
playlists:(‘carl’, ‘jams’, ‘Undone’, 2015-09-24 9:00)
last_played:(‘carl’, ‘jams’, 2015-09-24 9:00, ‘Undone’)
Query existing last_played
Query existing last_played
Manual Denormalization: Contentious Updates
Client 1
Cassandra
Client 2
playlists:(‘carl’, ‘jams’, ‘Undone’, 2015-09-24 9:02)
last_played:(‘carl’, ‘jams’, 2015-09-24 9:01, ‘Undone’)
last_played:(‘carl’, ‘jams’, 2015-09-24 9:02, ‘Undone’)
Update last played time to 9:02
last_played: 2015-09-24 9:00
last_played: 2015-09-24 9:00
Update last played time to 9:01
Manual Denormalization Limitations
Materialized Views
• Provide automated server-side denormalization
• No need for read-before-write on the application side
• Simplify application code
• Provide safer guarantees
Materialized Views: Guarantees
• If a write is acknowledged, at least CL number of base and
view replicas will receive the write
• If a write is actually an update, the previous value will be
cleaned up in the view
• Even with contentious updates, view synchronized with base
for each update
• Takes care of deletions properly
• When a base table is repaired, the data will also be inserted
into the view
• TTL’d base data will remain TTL’d in view
Why Not Just Use Secondary Indexes?
• We can get most of the same functionality by using
secondary indexes
• Secondary indexes query each node, not being able to use
the ring
• On a node, not a single access
Secondary Indexes: Query Pattern
Client
Secondary Indexes: Query Pattern
Client
Secondary Indexes: Query Pattern
Client
Materialized Views: Query Pattern
Client
Materialized Views in Practice
CREATE TABLE playlists
(user_name text,
playlist_name text,
song_id text,
artist_name text,
last_played timestamp,
PRIMARY KEY (user_name, playlist_name, song_id))
Materialized Views in Practice
CREATE MATERIALIZED VIEW artist_to_user AS
SELECT song_id, user_name
FROM playlists
WHERE song_id IS NOT NULL
AND playlist_name IS NOT NULL
AND user_name IS NOT NULL
AND artist_name IS NOT NULL
PRIMARY KEY (artist_name, user_name, playlist_name, song_id)
Replica Placement
user_name:carl
Replica Placement
artist_name:Weezer
user_name:carl
Materialized Views in Practice
• On creation, a new materialized view will be populated with
existing base data
• Each node tracks the completion of the build independently
SELECT *
FROM system.built_views
WHERE keyspace=‘ks’
AND view_name=‘view’
Materialized Views in Practice
CREATE MATERIALIZED VIEW last_played AS
SELECT last_played, song_id
FROM playlists
WHERE user_name IS NOT NULL
AND last_played IS NOT NULL
AND song_id IS NOT NULL
PRIMARY KEY (user_name, playlist_name, last_played, song_id)
CLUSTERING ORDER BY (last_played DESC)
Materialized Views: Performance
• https://github.com/tjake/mvbench
• Uses java-driver to simulate MV and manual denormalization
Materialized Views: Performance (ops/s)
Manual Denormalization
Materialized Views
Materialized Views: Performance (p95 latency)
Manual Denormalization
Materialized Views
• Adding WHERE clause support (#9664)
CREATE MATERIALIZED VIEW carls_last_played AS
SELECT last_played, song_id
FROM plays
WHERE user_name=‘carl’
PRIMARY KEY (last_played, song_id)
• Knowing when a view is completely finished building without
querying each node (#9967)
• Insert only tables can skip read-before-write, lock acquisition
(#9779)
Materialized Views: Future Features
write<p1, p2, c1, c2, v1>
Node A Node B Node C
Coordinator
Base
View
Node D
write<p1, p2, c1, c2, v1>
del<v0, p1, p2, c1, c2>
Client
write<v1, p1, p2, c1, c2>
BL
Materialized Views: Under the Hood
• If update is partial, we will reinsert data from the read when
generating a new row
• If no tombstone generated, only new columns are written
to view
Materialized Views: The Edge
• Materialized Views have different failure properties than the
rest of the system
• Data from a single base replica can be on many view replicas
Materialized Views: The Edge
• When data is lost on all replicas of the base table, it can not
be cleaned up in the view (#10346)
• No read repair between the base and the view table
• Repair of base table will clean up view
• Requires local read-before-write.
• If you will never ever update/delete use manual MVs
Materialized Views: The Edge
• An update from a base table is asynchronously applied to the
view, so it is possible there will be a delay
• A MV on a low-cardinality table can cause hotspots in the
ring, overloading some nodes
Thanks

More Related Content

What's hot

ETL With Cassandra Streaming Bulk Loading
ETL With Cassandra Streaming Bulk LoadingETL With Cassandra Streaming Bulk Loading
ETL With Cassandra Streaming Bulk Loading
alex_araujo
 
Understanding How CQL3 Maps to Cassandra's Internal Data Structure
Understanding How CQL3 Maps to Cassandra's Internal Data StructureUnderstanding How CQL3 Maps to Cassandra's Internal Data Structure
Understanding How CQL3 Maps to Cassandra's Internal Data Structure
DataStax
 

What's hot (20)

From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
 
ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022ProxySQL Cluster - Percona Live 2022
ProxySQL Cluster - Percona Live 2022
 
Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3
 
Understanding Data Partitioning and Replication in Apache Cassandra
Understanding Data Partitioning and Replication in Apache CassandraUnderstanding Data Partitioning and Replication in Apache Cassandra
Understanding Data Partitioning and Replication in Apache Cassandra
 
Storing time series data with Apache Cassandra
Storing time series data with Apache CassandraStoring time series data with Apache Cassandra
Storing time series data with Apache Cassandra
 
Building a Feature Store around Dataframes and Apache Spark
Building a Feature Store around Dataframes and Apache SparkBuilding a Feature Store around Dataframes and Apache Spark
Building a Feature Store around Dataframes and Apache Spark
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeper
 
Cassandra Introduction & Features
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & Features
 
Native Support of Prometheus Monitoring in Apache Spark 3.0
Native Support of Prometheus Monitoring in Apache Spark 3.0Native Support of Prometheus Monitoring in Apache Spark 3.0
Native Support of Prometheus Monitoring in Apache Spark 3.0
 
Redis + Apache Spark = Swiss Army Knife Meets Kitchen Sink
Redis + Apache Spark = Swiss Army Knife Meets Kitchen SinkRedis + Apache Spark = Swiss Army Knife Meets Kitchen Sink
Redis + Apache Spark = Swiss Army Knife Meets Kitchen Sink
 
ETL With Cassandra Streaming Bulk Loading
ETL With Cassandra Streaming Bulk LoadingETL With Cassandra Streaming Bulk Loading
ETL With Cassandra Streaming Bulk Loading
 
Using Apache Hive with High Performance
Using Apache Hive with High PerformanceUsing Apache Hive with High Performance
Using Apache Hive with High Performance
 
Spark + Parquet In Depth: Spark Summit East Talk by Emily Curtin and Robbie S...
Spark + Parquet In Depth: Spark Summit East Talk by Emily Curtin and Robbie S...Spark + Parquet In Depth: Spark Summit East Talk by Emily Curtin and Robbie S...
Spark + Parquet In Depth: Spark Summit East Talk by Emily Curtin and Robbie S...
 
Bucket your partitions wisely - Cassandra summit 2016
Bucket your partitions wisely - Cassandra summit 2016Bucket your partitions wisely - Cassandra summit 2016
Bucket your partitions wisely - Cassandra summit 2016
 
Troubleshooting redis
Troubleshooting redisTroubleshooting redis
Troubleshooting redis
 
10 Good Reasons to Use ClickHouse
10 Good Reasons to Use ClickHouse10 Good Reasons to Use ClickHouse
10 Good Reasons to Use ClickHouse
 
How to Actually Tune Your Spark Jobs So They Work
How to Actually Tune Your Spark Jobs So They WorkHow to Actually Tune Your Spark Jobs So They Work
How to Actually Tune Your Spark Jobs So They Work
 
Edge architecture ieee international conference on cloud engineering
Edge architecture   ieee international conference on cloud engineeringEdge architecture   ieee international conference on cloud engineering
Edge architecture ieee international conference on cloud engineering
 
Understanding How CQL3 Maps to Cassandra's Internal Data Structure
Understanding How CQL3 Maps to Cassandra's Internal Data StructureUnderstanding How CQL3 Maps to Cassandra's Internal Data Structure
Understanding How CQL3 Maps to Cassandra's Internal Data Structure
 
Enabling Vectorized Engine in Apache Spark
Enabling Vectorized Engine in Apache SparkEnabling Vectorized Engine in Apache Spark
Enabling Vectorized Engine in Apache Spark
 

Viewers also liked

Light Weight Transactions Under Stress (Christopher Batey, The Last Pickle) ...
Light Weight Transactions Under Stress  (Christopher Batey, The Last Pickle) ...Light Weight Transactions Under Stress  (Christopher Batey, The Last Pickle) ...
Light Weight Transactions Under Stress (Christopher Batey, The Last Pickle) ...
DataStax
 
Whats A Data Warehouse
Whats A Data WarehouseWhats A Data Warehouse
Whats A Data Warehouse
None None
 
Data Warehouse and OLAP - Lear-Fabini
Data Warehouse and OLAP - Lear-FabiniData Warehouse and OLAP - Lear-Fabini
Data Warehouse and OLAP - Lear-Fabini
Scott Fabini
 
Cassandra background-and-architecture
Cassandra background-and-architectureCassandra background-and-architecture
Cassandra background-and-architecture
Markus Klems
 

Viewers also liked (20)

Cassandra and materialized views
Cassandra and materialized viewsCassandra and materialized views
Cassandra and materialized views
 
Cassandra UDF and Materialized Views
Cassandra UDF and Materialized ViewsCassandra UDF and Materialized Views
Cassandra UDF and Materialized Views
 
Cassandra Data Modeling - Practical Considerations @ Netflix
Cassandra Data Modeling - Practical Considerations @ NetflixCassandra Data Modeling - Practical Considerations @ Netflix
Cassandra Data Modeling - Practical Considerations @ Netflix
 
Data Modeling for Data Science: Simplify Your Workload with Complex Types in ...
Data Modeling for Data Science: Simplify Your Workload with Complex Types in ...Data Modeling for Data Science: Simplify Your Workload with Complex Types in ...
Data Modeling for Data Science: Simplify Your Workload with Complex Types in ...
 
User defined-functions-cassandra-summit-eu-2014
User defined-functions-cassandra-summit-eu-2014User defined-functions-cassandra-summit-eu-2014
User defined-functions-cassandra-summit-eu-2014
 
Light Weight Transactions Under Stress (Christopher Batey, The Last Pickle) ...
Light Weight Transactions Under Stress  (Christopher Batey, The Last Pickle) ...Light Weight Transactions Under Stress  (Christopher Batey, The Last Pickle) ...
Light Weight Transactions Under Stress (Christopher Batey, The Last Pickle) ...
 
Tc de literatura6º
Tc de literatura6ºTc de literatura6º
Tc de literatura6º
 
台灣政黨票立委席次分配方式
台灣政黨票立委席次分配方式台灣政黨票立委席次分配方式
台灣政黨票立委席次分配方式
 
Advanced search and Top-K queries in Cassandra
Advanced search and Top-K queries in CassandraAdvanced search and Top-K queries in Cassandra
Advanced search and Top-K queries in Cassandra
 
05 OLAP v6 weekend
05 OLAP  v6 weekend05 OLAP  v6 weekend
05 OLAP v6 weekend
 
FedX - Optimization Techniques for Federated Query Processing on Linked Data
FedX - Optimization Techniques for Federated Query Processing on Linked DataFedX - Optimization Techniques for Federated Query Processing on Linked Data
FedX - Optimization Techniques for Federated Query Processing on Linked Data
 
Whats A Data Warehouse
Whats A Data WarehouseWhats A Data Warehouse
Whats A Data Warehouse
 
Introduction to Cassandra Architecture
Introduction to Cassandra ArchitectureIntroduction to Cassandra Architecture
Introduction to Cassandra Architecture
 
Postgre sql9.3新機能紹介
Postgre sql9.3新機能紹介Postgre sql9.3新機能紹介
Postgre sql9.3新機能紹介
 
Data Warehouse and OLAP - Lear-Fabini
Data Warehouse and OLAP - Lear-FabiniData Warehouse and OLAP - Lear-Fabini
Data Warehouse and OLAP - Lear-Fabini
 
Oracle Optimizer: 12c New Capabilities
Oracle Optimizer: 12c New CapabilitiesOracle Optimizer: 12c New Capabilities
Oracle Optimizer: 12c New Capabilities
 
Materialized views in PostgreSQL
Materialized views in PostgreSQLMaterialized views in PostgreSQL
Materialized views in PostgreSQL
 
Cassandra background-and-architecture
Cassandra background-and-architectureCassandra background-and-architecture
Cassandra background-and-architecture
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Python and cassandra
Python and cassandraPython and cassandra
Python and cassandra
 

Similar to Cassandra Materialized Views

Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptxShshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
086ChintanPatel1
 

Similar to Cassandra Materialized Views (20)

Cassandra Basics, Counters and Time Series Modeling
Cassandra Basics, Counters and Time Series ModelingCassandra Basics, Counters and Time Series Modeling
Cassandra Basics, Counters and Time Series Modeling
 
Deep Dive into Cassandra
Deep Dive into CassandraDeep Dive into Cassandra
Deep Dive into Cassandra
 
Flink Forward Berlin 2017: Fabian Hueske - Using Stream and Batch Processing ...
Flink Forward Berlin 2017: Fabian Hueske - Using Stream and Batch Processing ...Flink Forward Berlin 2017: Fabian Hueske - Using Stream and Batch Processing ...
Flink Forward Berlin 2017: Fabian Hueske - Using Stream and Batch Processing ...
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops Exploring the Fundamentals of YugabyteDB - Mydbops
Exploring the Fundamentals of YugabyteDB - Mydbops
 
Migrating To PostgreSQL
Migrating To PostgreSQLMigrating To PostgreSQL
Migrating To PostgreSQL
 
Sql server basics
Sql server basicsSql server basics
Sql server basics
 
Dan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New FeaturesDan Hotka's Top 10 Oracle 12c New Features
Dan Hotka's Top 10 Oracle 12c New Features
 
SQL Server 2014 Monitoring and Profiling
SQL Server 2014 Monitoring and ProfilingSQL Server 2014 Monitoring and Profiling
SQL Server 2014 Monitoring and Profiling
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptxShshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
Shshsjsjsjs-4 - Copdjsjjsjsjsjakakakaaky.pptx
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behl
 
How and when to use NoSQL
How and when to use NoSQLHow and when to use NoSQL
How and when to use NoSQL
 
Couchbas for dummies
Couchbas for dummiesCouchbas for dummies
Couchbas for dummies
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
 
How & When to Use NoSQL at Websummit Dublin
How & When to Use NoSQL at Websummit DublinHow & When to Use NoSQL at Websummit Dublin
How & When to Use NoSQL at Websummit Dublin
 
MWLUG 2016 : AD117 : Xpages & jQuery DataTables
MWLUG 2016 : AD117 : Xpages & jQuery DataTablesMWLUG 2016 : AD117 : Xpages & jQuery DataTables
MWLUG 2016 : AD117 : Xpages & jQuery DataTables
 
Sap abap
Sap abapSap abap
Sap abap
 
SQL Server 2016 novelties
SQL Server 2016 noveltiesSQL Server 2016 novelties
SQL Server 2016 novelties
 
Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 

Recently uploaded (20)

Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Cassandra Materialized Views

  • 2. What are Materialized Views? • Two copies of the data using different partitioning and placed on different replicas • Automated, server-side denormalization of data • Native Cassandra read performance • Write penalty, but acceptable performance
  • 3. Basic Rules of Data Modeling, Refresher • Best practice: Denormalization • Start by understanding the queries you need • Create a table for each query
  • 4. Why is Denormalization Hard? • Implemented by every application • No guarantees on performance or consistency • Updates to existing rows require cleanup, read-before-write
  • 5. Denormalization Example: User Playlists Queries • All Songs for a given playlist • Track Users who like the same Artist • Find most recently played song
  • 6. Denormalization in Practice CREATE TABLE playlists (user_name text, playlist_name text, song_id text, artist_name text, last_played timestamp) SELECT song_id FROM playlists WHERE user_name=‘carl’ AND playlist_name=‘jams’ SELECT COUNT(song_id) FROM playlists WHERE artist_name=‘Weezer’ SELECT last_played, song_id FROM playlists WHERE user_name=‘carl’ AND playlist_name=‘jams’ ORDER BY last_played DESC
  • 7. Denormalization in Practice CREATE TABLE playlists (user_name text, playlist_name text, song_id text, artist_name text, last_played timestamp, PRIMARY KEY (user_name, playlist_name, song_id)) CREATE TABLE artists_to_playlists (artist_name text, user_name text, playlist_name text, song_id text, PRIMARY KEY (artist_name, user_name, playlist_name, song_id))
  • 8. Denormalization in Practice CREATE TABLE last_played (user_name text, playlist_name text, last_played timestamp, song_id text, PRIMARY KEY (user_name, playlist_name, last_played, song_id)) CLUSTERING ORDER BY (last_played DESC)
  • 9. Denormalization in Practice: Inserts BEGIN BATCH INSERT INTO playlists (user_name, playlist_name, song_id, artist_name, last_played) VALUES (‘carl’, ‘jams’, ‘Undone’, ‘Weezer’, ‘2015-09-24 09:00’); INSERT INTO artists_by_playlist (artist_name, user_name, playlist_name, song_id) VALUES (‘Weezer’, ‘carl’, ‘jams’, ‘Undone’); INSERT INTO last_played (user_name, playlist_name, last_played, song_id) VALUES (‘carl’, ‘jams’, ‘Undone’, ‘2015-09-24 09:00’); APPLY BATCH;
  • 10. Denormalization in Concept: Updates UPDATE playlists SET last_updated=now() WHERE user_name=‘carl’ AND playlist_name=‘jams’ AND song_id=‘Undone’ DELETE FROM playlists WHERE user=‘carl’
  • 11. Manual Denormalization with updates Client Batchlog Base Table View Table Coordinator
  • 12. Manual Denormalization with updates Client Batchlog Base Table View Table Coordinator Query Existing Data
  • 13. Manual Denormalization with updates Client Batchlog Base Table View Table Coordinator Query Existing Data Query Existing Data
  • 14. Manual Denormalization with updates Client Batchlog Base Table View Table Coordinator Query Existing Data Query Existing Data Return Existing Data Return Existing Data
  • 15. Manual Denormalization with updates Client Batchlog Base Table View Table Coordinator Write New Values
  • 16. Manual Denormalization with updates Client Batchlog Base Table View Table Coordinator Write New Values Write New Values
  • 17. Manual Denormalization with updates Client Batchlog View Table Coordinator Write New Values Write New Values Base Table Write New Values
  • 19. Manual Denormalization Limitations • Updates need to keep view in sync, including tombstoning previous values • How to keep the view and base in sync on failure? • Contentious updates can potentially cause extra values • Your application doesn’t always know what is a update or an insert (i.e. upsert)
  • 20. Manual Denormalization: Contentious Updates Client 1 Cassandra Client 2 playlists:(‘carl’, ‘jams’, ‘Undone’, 2015-09-24 9:00) last_played:(‘carl’, ‘jams’, 2015-09-24 9:00, ‘Undone’) Query existing last_played Query existing last_played
  • 21. Manual Denormalization: Contentious Updates Client 1 Cassandra Client 2 playlists:(‘carl’, ‘jams’, ‘Undone’, 2015-09-24 9:02) last_played:(‘carl’, ‘jams’, 2015-09-24 9:01, ‘Undone’) last_played:(‘carl’, ‘jams’, 2015-09-24 9:02, ‘Undone’) Update last played time to 9:02 last_played: 2015-09-24 9:00 last_played: 2015-09-24 9:00 Update last played time to 9:01
  • 23. Materialized Views • Provide automated server-side denormalization • No need for read-before-write on the application side • Simplify application code • Provide safer guarantees
  • 24. Materialized Views: Guarantees • If a write is acknowledged, at least CL number of base and view replicas will receive the write • If a write is actually an update, the previous value will be cleaned up in the view • Even with contentious updates, view synchronized with base for each update • Takes care of deletions properly • When a base table is repaired, the data will also be inserted into the view • TTL’d base data will remain TTL’d in view
  • 25. Why Not Just Use Secondary Indexes? • We can get most of the same functionality by using secondary indexes • Secondary indexes query each node, not being able to use the ring • On a node, not a single access
  • 26. Secondary Indexes: Query Pattern Client
  • 27. Secondary Indexes: Query Pattern Client
  • 28. Secondary Indexes: Query Pattern Client
  • 29. Materialized Views: Query Pattern Client
  • 30. Materialized Views in Practice CREATE TABLE playlists (user_name text, playlist_name text, song_id text, artist_name text, last_played timestamp, PRIMARY KEY (user_name, playlist_name, song_id))
  • 31. Materialized Views in Practice CREATE MATERIALIZED VIEW artist_to_user AS SELECT song_id, user_name FROM playlists WHERE song_id IS NOT NULL AND playlist_name IS NOT NULL AND user_name IS NOT NULL AND artist_name IS NOT NULL PRIMARY KEY (artist_name, user_name, playlist_name, song_id)
  • 34. Materialized Views in Practice • On creation, a new materialized view will be populated with existing base data • Each node tracks the completion of the build independently SELECT * FROM system.built_views WHERE keyspace=‘ks’ AND view_name=‘view’
  • 35. Materialized Views in Practice CREATE MATERIALIZED VIEW last_played AS SELECT last_played, song_id FROM playlists WHERE user_name IS NOT NULL AND last_played IS NOT NULL AND song_id IS NOT NULL PRIMARY KEY (user_name, playlist_name, last_played, song_id) CLUSTERING ORDER BY (last_played DESC)
  • 36. Materialized Views: Performance • https://github.com/tjake/mvbench • Uses java-driver to simulate MV and manual denormalization
  • 37. Materialized Views: Performance (ops/s) Manual Denormalization Materialized Views
  • 38. Materialized Views: Performance (p95 latency) Manual Denormalization Materialized Views
  • 39. • Adding WHERE clause support (#9664) CREATE MATERIALIZED VIEW carls_last_played AS SELECT last_played, song_id FROM plays WHERE user_name=‘carl’ PRIMARY KEY (last_played, song_id) • Knowing when a view is completely finished building without querying each node (#9967) • Insert only tables can skip read-before-write, lock acquisition (#9779) Materialized Views: Future Features
  • 40. write<p1, p2, c1, c2, v1> Node A Node B Node C Coordinator Base View Node D write<p1, p2, c1, c2, v1> del<v0, p1, p2, c1, c2> Client write<v1, p1, p2, c1, c2> BL
  • 41. Materialized Views: Under the Hood • If update is partial, we will reinsert data from the read when generating a new row • If no tombstone generated, only new columns are written to view
  • 42. Materialized Views: The Edge • Materialized Views have different failure properties than the rest of the system • Data from a single base replica can be on many view replicas
  • 43. Materialized Views: The Edge • When data is lost on all replicas of the base table, it can not be cleaned up in the view (#10346) • No read repair between the base and the view table • Repair of base table will clean up view • Requires local read-before-write. • If you will never ever update/delete use manual MVs
  • 44. Materialized Views: The Edge • An update from a base table is asynchronously applied to the view, so it is possible there will be a delay • A MV on a low-cardinality table can cause hotspots in the ring, overloading some nodes