The Last Pickle: Repeatable, Scalable, Reliable, Observable: Cassandra
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cassandra, C# and Azure
-
Upload
planet-cassandra -
Category
Technology
-
view
277 -
download
1
description
Transcript of Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cassandra, C# and Azure
Highly Scalable Web Application in the Cloud with Cassandra, C# and Azure
Luke Tillman (@LukeTillman) Language Evangelist, DataStax
Jeremiah Talkar (@JST2Cents)
Azure Evangelist, Microsoft
KillrVideo Intro and Demo www.killrvideo.com
.NET and Cassandra • Open Source (on GitHub), available via NuGet
• Bootstrap using the Builder and then reuse the ISession object
Cluster cluster = Cluster.Builder() .AddContactPoint("127.0.0.1") .Build(); ISession session = cluster.Connect("killrvideo");
.NET and Cassandra • Executing CQL
• Sync and Async API available
var statement = new SimpleStatement("SELECT * FROM users WHERE userid = ?"); statement = statement.Bind(145); RowSet rows = await session.ExecuteAsync(statement);
.NET and Cassandra • PROTIP: Prepared Statements are your friend
• Prepare once (server roundtrip), Bind and Execute many
• Remember: Save and reuse your Prepared Statement instances
PreparedStatement prepared = session.Prepare("SELECT * FROM users WHERE userid = ?");
BoundStatement boundStatement = prepared.Bind(145); RowSet rows = await session.ExecuteAsync(boundStatement);
.NET and Cassandra • Getting values from a RowSet is easy
• Rowset is a collection of Row (IEnumerable<Row>)
RowSet rows = await _session.ExecuteAsync(boundStatement); foreach (Row row in rows) { var videoId = row.GetValue<Guid>("videoid"); var addedDate = row.GetValue<DateTimeOffset>("added_date"); var name = row.GetValue<string>("name"); }
.NET and Cassandra • Mapping results to DTOs: if you like using CQL, try CqlPoco package
• Note: This package may be pulled into the official driver soon.
public class User { public Guid UserId { get; set; } public string Name { get; set; } } // Get a user by id from Cassandra or null if not found var user = client.SingleOrDefault<User>( "SELECT userid, name FROM users WHERE userid = ?", someUserId);
.NET and Cassandra • Mapping results to DTOs: if you like LINQ, use built-in LINQ provider
[Table("users")] public class User { [Column("userid"), PartitionKey] public Guid UserId { get; set; } [Column("name")] public string Name { get; set; } } var user = session.GetTable<User>() .SingleOrDefault(u => u.UserId == someUserId) .Execute();
Remember… • Prepared Statements are a great performance optimization but
remember to Prepare once, Bind and Execute many
• Take advantage of the async API to give your web server a break or run queries in parallel
• Don’t write boilerplate mapping code—use LINQ or CqlPoco
KillrVideo on Azure
Cassandra Cluster (DSE)
App data storage (video metadata, comments, users,
ratings, etc.)
Azure Media Services
Uploaded video encoding, thumbnail generation, Video
access URI generation
Azure Storage
Queues – notifications on encoding job progress
Blob – uploaded video storage
OpsCenter
provisioning, monitoring,
management
KillrVideo Web App C# MVC Web Application, Azure Web Role
Serves up UI, JSON Endpoints
KillrVideo Upload Worker C#, Azure Worker Role
Monitors encoding job events, publishes completed
uploads
Web UI HTML5 / JavaScript (KnockoutJS, jQuery, Bootstrap, etc)
Microsoft Azure
Why Azure? • Enterprise Business
• Hybrid story, not Cloud only, via single cloud platform model
• Broadest Reach via Azure regions footprint, global hosting partners and on premises
• Azure Active Directory
• Richness of finished services O365, Azure Mobile Services, Azure Notification Services, Azure API Management, Azure Media Services, Device Hub, etc.
Next Steps • Get the code and schema on GitHub
https://github.com/luketillman/killrvideo-csharp
• Use the live demo hosted in Azure
http://www.killrvideo.com
• Sign up for free Azure trial subscription
http://azure.microsoft.com