Topics:

DataStax Enterprise
Apache Cassandra
Data Modeling
Analytics
Search
Reference Application
C# / .NET
Microsoft Azure

About this Tutorial

KillrVideo is a sample application developed in C# and uses DataStax Enterprise running on Microsoft Azure. The application demonstrates a number of DataStax Enterprise components in action including Apache Cassandra DSE Analytics, and DSE Search.

The Killr Video application is a sample web application developed in C# and uses DataStax Enterprise (DSE) running on Microsoft Azure as the database platform. The application demonstrates a number of DataStax Enterprise components in action including Apache Cassandra, DSE Analytics, and DSE Search.

The use cases modeled by the application include product catalog and playlists, personalization and recommendations, and user activity analysis. Educational links and materials for KillrVideo include:

In the talk and slides below Luke Tillman (@LukeTillman) walks through the process of building KillrVideo, an open source video sharing website where users can upload and share videos, rate them, comment on them, and more. By looking at a real application, we’ll talk about architectural decisions, how the application drives the data model, some pro tips when using the DataStax drivers, and some lessons learned from mistakes made along the way.

Running Locally

Once you've cloned the repository, you'll need to do a few things to get up and running locally.

Install DataStax Enterprise

You'll need a running Apache Cassandra™ cluster. For local development, that cluster can just be a single node running on your local machine. The easiest way to get started is with DataStax Enterprise, which you can use for free in development. If you're on Windows and you'd like more details on installing and developing, check out my blog post aptly titled Developing with Cassandra on Windows.

Install the Microsoft Azure SDK

The Microsoft Azure SDK will allow you to run Azure web/worker roles via an emulator on your local machine. If you don't already have it, you'll need to install it.

Create Azure Services keys

KillrVideo makes use of a number of Microsoft Azure services. As a result, you'll need to provision the appropriate resources in the Azure Management Portal under your account. If you don't already have an Azure account, you can get a free trial of Azure from Microsoft. From the management portal, you'll need to create:

  • An Azure Storage account to use for Azure Media Services. This is used to store uploaded videos from the app.
  • An Azure Media Services account. The portal will ask you to select an Azure Storage account when you create the Media Services account (select the one you just created previously). This is used to process and encode uploaded videos for playback.
  • An Azure Service Bus namespace. This is used for communication between services (via events) in the application.

Create a YouTube API key

KillrVideo allows adding videos to the site from sources other than uploads (for example, YouTube). As a result, you'll need to create a YouTube API key. Follow the instructions from Google for creating a project and adding a key in the Google Developers console.

Note: You don't need an OAuth 2.0 key, just a regular API key. You'll want to create a Browser Key when prompted by the console.

Create the KillrVideo schema in Cassandra

Run the schema.cql script in the data/ folder against your Cassandra cluster to create the appropriate schema. For example (via CQL Shell):

cqlsh -f schema.cql

If you'd like a GUI for exploring Cassandra (and running the CQL script to create the schema), check out the free Dev Centertool for developers.

Configure the KillrVideo Application

You'll need to configure your local copy of KillrVideo with the correct connection strings and API keys that you created. Here are the steps:

  1. Under the /src/KillrVideo.Azure folder, find the ServiceConfiguration.Local.Transform.cscfg.template configuration transform file. Make a copy and rename it to ServiceConfiguration.Local.Transform.cscfg (i.e. remove the .templatefile extension).
  2. Edit the ServiceConfiguration.Local.Transform.cscfg transformation file you just created and fill in the values for your local environment. You'll need to provide:
    • CassandraClusterLocation: the IP/DNS for your Cassandra cluster (for example, 127.0.0.1).
    • AzureMediaServicesAccountName: the account name for your Azure Media Services account.
    • AzureMediaServicesAccountKey: the secret key for your Azure Media Services account
    • AzureStorageConnectionString: the connection string for the Storage account that's linked to your Azure Media Services account.
    • AzureServiceBusConnectionString: the connection string for the Service Bus namespace that you created.
    • YouTubeApiKey: the YouTube API key that you created.

Run KillrVideo

Open KillrVideo.sln in Visual Studio. Right-click on the KillrVideo.Azure project and set it as the startup project. Press F5 to launch the KillrVideo.Azure project with a debugger attached. It should launch the Azure Emulator and IIS Express by default. The web site will run on 127.0.0.1 by default.

Adding Sample Data to KillrVideo

KillrVideo contains a SampleData service that will periodically add sample YouTube videos, users, comments, etc. to the site on a schedule. The first time you run the application, some of that data should be added (you will probably need to refresh the home page of the web application after about 30 seconds to see the initial sample videos). When running locally, you can also manually trigger adding sample data to the site using the Add Sample Data link in the footer of the site.

Enabling uploads to Azure Media Services

When uploading videos to share, the client-side JavaScript uploads directly to Azure Storage (bypassing the KillrVideo web app) so as not to put additional strain on the web server just for video uploads. It does this by taking advantage of CORS-enabled uploads for Azure Media Services. For this to work, you'll need to add a CORS rule to your Azure Storage account. Unfortunately, you can't manage these rules via the Azure Management Portal UI, however someone else has built a simple UI for managing these rules.

  1. Grab the Azure CORS Rule Manager web app from GitHub.
  2. Open it in Visual Studio and run it (no configuration is needed to launch the app).
  3. Enter the credentials for the Azure Storage account linked to your Azure Media Services account.
  4. Add a CORS rule (modify these to fit your local settings):