Getting Started with DataStax Astra
So you’ve got an amazing idea for your hackathon project and realize that you’ll probably need a database to bring everything together. If you’re relatively new to programming and/or full stack development, this topic may seem daunting at first, but hold tight because this article was written with you in mind. Not only will this walk-through show you the ins and outs of getting started with DataStax Astra, a cloud-native database service built with open-source Cassandra, it will also get you underway to winning the Best Use Of DataStax prize category at participating MLH events.
Whether you’ve used an online database in the past or not, getting started with DataStax Astra is quick and simple. In this guide, I’ll be walking you through the platform sign-up, database set-up and how to access your database from your application. By the end you’ll have an elastically scalable Cassandra database that can handle even the largest data sets. All you’ll need for now is a computer, an internet connection and maybe a snack of your choice (to keep you occupied while DataStax does the heavy lifting).
Registration
First things first, let’s head over to https://astra.datastax.com/register to register our accounts with DataStax.
Once logged in, you’ll be directed over to your dashboard where you’ll see an ‘Add Database’ button on the right hand side. The images below should give you a better idea of the workflow:
Now that we’ve gotten this far, let’s familiarize ourselves with the Configure and Create Database fields.
Database name: When creating your database name, it is important to note that you cannot change it moving forward. The name itself will need to remain unique to your user profile so try to avoid generic naming conventions such as “database” or “myDatabase.” After all, your user profile may contain multiple databases in the future.
Keyspace name: This identifier signifies a subset within your database that will be used to store tables. This keyspace will permanently live in your database until you delete it or the database itself. If you want your keyspace to have a case-sensitive name, make sure you wrap it in quotes, otherwise it will default to lowercase.
Database username and password: These credentials will be used to gain access to your database along with the developer tools available to registered DataStax users.
Go ahead and launch your database when you’re ready!
Your Astra Dashboard
Your Astra Database dashboard should now have a card for your new database. Feel free to hit the connect button and select the ‘Summary’ tab to take a closer look at your database details.
*For reference, a Cassandra database is spread across several machines that work in concert with one another. The more space you require, the more machines Cassandra puts to use, making it an elastically scalable solution that is extremely useful for dynamic data storage. In order to keep track of your data distribution, Cassandra takes the nodes of information within your database and arranges them in a container, also known as a cluster.
You will see that there are four tabs on the top left corner of your database dashboard screen. The CQL Console tab and Health tab respectively contain Astra’s built in CQL terminal and your database cluster activity. Let’s take a look!
Using the CQL Console
CQL, or Cassandra Query Language, is the syntax you will use to interact with your DataStax Astra database. If you have any experience with Structured Query Language (SQL) used for relational database management, you will find that CQL is very similar and easy to learn. For your convenience, DataStax has prepared a run-down of some of the most commonly used CQL commands for you.
There are many options for you to get started but if you are already familiar with database management systems and are comfortable with SQL, the easiest way to begin interacting with your Astra database is through DataStax’ built-in CQL Console. Just click to the right of the summary tab.
Get Rosendo Pili’s stories in your inbox
Join Medium for free to get updates from this writer.
Your CQL Console will look like this:
Take note that the prompt for your password may take a few seconds to populate after you input a username. Datastax is simply establishing a connection with your machine. Additionally, you will not receive any feedback from the console as you input your password. This is a security feature of the console meant to hide your password length. Simply type in your password and press enter.
Upon successful login with cqlsh, you will receive a confirmation that you have connected to caas-cluster:
You can now begin to create new tables in your keyspace using CQL syntax.
Creating a Table with CQL
We can start off by creating a simple data table called people. You will note that CQL uses dot notation to create a table within the keyspace entitled myhackathonproject.
CREATE TABLE myhackathonproject.people (
id int PRIMARY KEY,
first text,
last text
);
Once the table is created, the CQL console will simply move your cursor to the next line. If you want a visible confirmation that your table was created, you can run the
SELECT * FROM myhackathonproject.people;
command (of course replacing myhackathonproject.people with your keyspace and table name).
We can now begin inserting rows:
INSERT INTO myhackathonproject.people (
id, first, last
) VALUES (
1, ‘Rosendo’, ‘Pili’
);
While the syntax is nearly identical to SQL you should note that DataStax Astra is a non-relational database and its query language does not support SQL style joins. Instead, each of your tables will contain a Primary Key and partition key(s) that are used to associate data within a node cluster.
Checking Your Cluster Health
Finally, you can come back to your Astra dashboard and check on your cluster activity using the ‘Health’ tab.
From there you will be directed to your Cluster Overview which will contain graphical representations of your database usage history. You shouldn’t see much activity at first, but once your application goes live, expect this page to get a lot more interesting. Additionally, you can head off any potential data leakage in your application by periodically checking your cluster health. Errant activity could denote that a bad actor and/or unauthorized user has gained access to your database or maybe one of your API fetch calls has run amuck and needs some refinement. Either way, the health tab can be very useful in diagnosing any potential issues with your full stack application.
With that being said, you should now have a fully functioning CQL database on the cloud, a dedicated keyspace to house your data and, to get even more granular, a data table within that keyspace that contains your data rows. Pretty sweet.
Connecting To Your Database
Astra REST API & Astra GraphQL API
As I mentioned before, DataStax provides some well-documented methods for you to leverage your database programmatically including the Astra REST API and the Astra GraphQL API. Let’s hit the connect button on the right hand side of your dashboard nav and check out some of Astra’s built-in connection methods.
For the REST API, all you need to do is follow along in your language of choice. With the GraphQL API, you can follow along using cURL. For both options, be sure to keep the following DB information on hand.
ASTRA_CLUSTER_ID=[my cluster ID]
ASTRA_CLUSTER_REGION=[my location]
ASTRA_DB_USERNAME=[my username]
ASTRA_DB_PASSWORD=[my password]
DataStax Drivers
If you want to integrate some queries directly into your code-base, another simple way to hook up with your Astra database is by using your custom DataStax Driver. From the Connection Method card, click the “Download Secure Connect Bundle” button.
This will generate a zip file that you can use to access your database:
DataStax has some solid documentation on how to leverage these drivers using both Python and JavaScript/Node. Below you can see my boiler plate implementation of both drivers based on the instructions and the output you can expect after inputting your database information and executing the code.
… And if you’re still unsure about your hack
Check out the conveniently located Sample App Gallery tab and see how other developers are leveraging DataStax Astra in their projects.
SUCCESS!
Congratulations! You’ve successfully executed a query to your DataStax Astra database from your application! For more resources around DataStax Astra, you can always reference their documentation. You are now well on your way to completing your hack and claiming the ‘Best Use Of DataStax’ prize category at your MLH event!

