August 28, 2013
What is an Index?
In Riak, the fastest way to access your data is by its key.
However, it’s often useful to be able to locate objects by some other value, such as a named collection of users. Let’s say that we have a user object stored under its username as the key (e.g.,
thevegan3000) and that this particular user is in the
Administrators group. If you wanted to be able to find all users, such as
thevegan3000 who are in the Administrators group, then you would add an index (let’s say,
user_group) and set it to
administrator for those users. Riak has a super-easy-to-use option called Secondary Indexes that allows you to do exactly this and it’s available when you use either the LevelDB or Memory backends.
Using Secondary Indexes
Secondary Indexes are available in the Riak APIs and all of the official Riak clients. Note that
user_group_bin when accessing the API because we’re storing a binary value (in most cases, a string).
Add and retrieve an index in the Ruby Client:
In the Python Client:
In the Java Client:
More Example Use Cases
Not only are indexes easy to use, they’re extremely useful:
- Reference all orders belonging to a customer
- Save the users who liked something or the things that a user liked
- Tag content in a Content Management System (CMS)
- Store a GeoHash of a specific length for fast geographic lookup/filtering without expensive Geospatial operations
- Time-series data where all observations collected within a time-frame are referenced in a particular index
What If I Can’t Use Secondary Indexes?
Indexing is great, but if you want to use the Bitcask backend or if Secondary Indexes aren’t performant enough, there are alternatives.
A G-Set Term-Based Inverted Index has the following benefits over a Secondary Index:
- Better read performance at the sacrifice of some write performance
- Less resource intensive for the Riak cluster
- Excellent resistance to cluster partition since CRDTs have defined sibling merge behavior
- Can be implemented on any Riak backend including Bitcask, Memory, and of course LevelDB
- Tunable via read and write parameters to improve performance
- Ideal when the exact index term is known
Implementation of a G-Set Term-Based Inverted Index
A G-Set CRDT (Grow Only Set Convergent/Commutative Replicated Data Type) is a thin abstraction on the Set data type (available in most language standard libraries). It has a defined method for merging conflicting values (i.e. Riak siblings), namely a union of the two underlying Sets. In Riak, the G-Set becomes the value that we store in our Riak cluster in a bucket, and it holds a collection of keys to the objects we’re indexing (such as
thevegan3000). The key that references this G-Set is the term that we’re indexing,
administrator. The bucket containing the serialized G-Sets accepts Riak siblings (potentially conflicting values) which are resolved when the index is read. Resolving the indexes involves merging the sibling G-Sets which means that keys cannot be removed from this index, hence the name: “Grow Only”.
administrator G-Set Values prior to merging, represented by sibling values in Riak
administrator G-Set Value post merge, represented by a resolved value in Riak
Great! Show me the code!
As a demonstration, we integrated this logic into a branch of the Riak Ruby Client. As mentioned before, since a G-Set is actually a very simple construct and Riak siblings are perfect to support the convergent properties of CRDTs, the implementation of a G-Set Term-Based Inverted Index is nearly trivial.
There’s a basic interface that belongs to a Grow Only Set in addition to some basic JSON serialization facilities (not shown):
Next there’s the actual implementation of the Inverted Index. The index put operation simply creates a serialized G-Set with the single index value into Riak, likely creating a sibling in the process.
The index get operation retrieves the index value. If there are siblings, it resolves them by merging the underlying G-Sets, as described above, and writes the resolved record back into Riak.
With the modified Ruby client, adding a Term-Based Inverted Index is just as easy as a Secondary Index. Instead of using
_bin to indicate a string index and we’ll use
_inv for our Term-Based Inverted Index.
Binary Secondary Index:
zombie.indexes['zip_bin'] << data['ZipCode']
Term-Based Inverted Index:
zombie.indexes['zip_inv'] << data['ZipCode']
The downsides of G-Set Term-Based Inverted Indexes versus Secondary Indexes
- There is no way to remove keys from an index
- Storing a key/value pair with a Riak Secondary index takes about half the time as putting an object with a G-Set Term-Based Inverted Index because the G-Set index involves an additional Riak put operation for each index being added
- The Riak object which the index refers to has no knowledge of which indexes have been applied to it
- It is possible; however, to update the metadata for the Riak object when adding its key to the G-Set
- There is no option for searching on a range of values (e.g., all
See the Secondary Index documentation for more details.
The downsides of G-Set Term-Based Inverted Indexes versus Riak Search:
Riak Search is an alternative mechanism for searching for content when you don’t know which keys you want.
- No advanced searching: wildcards, boolean queries, range queries, grouping, etc
See the Riak Search documentation for more details.
Let’s see some graphs.
The graph below shows the average time to put an object with a single index and to retrieve a random index from the body of indexes that have already been written. The times include the client-side merging of index object siblings. It’s clear that although the put times for an object + G-Set Term-Based Inverted Index are roughly double than that of an object with a Secondary Index, the index retrieval times are less than half. This suggests that secondary indexes would be better for write-heavy loads but the G-Set Term-Based Inverted Indexes are much better where the ratio of reads is greater than the number of writes.
Over the length of the test, it is even clearer that G-Set Term-Based Inverted Indexes offer higher performance than Secondary Indexes when the workload of Riak skews toward reads. The use of G-Set Term-Based Inverted Indexes is very compelling even when you consider that the index merging is happening on the client-side and could be moved to the server for greater performance.
- Implement other CRDT Sets that support deletion
- Implement G-Set Term-Based Indexes as a Riak Core application so merges can run alongside the Riak cluster
- Implement strategies for handling large indexes such as term partitioning
August 21, 2013
Riak is being used by companies of all shapes and sizes. Since it is open source, we don’t know exactly how many deployments of Riak there are, but our best guess puts it in the thousands. We love hearing about all the unique ways companies are using Riak. Sometimes, our awesome users and partners even write up blogs that showcase how they’re using Riak and why they decided to give it a try. Below are a few good ones that we came across:
Our partner, SoftLayer, has written about Riak a number of times. Recently, Marc Jones wrote about some popular use cases for Riak and Harold Hannon wrote a performance analysis about running Riak on bare metal.
You can learn more about how Basho partners with SoftLayer here.
Flyclops is currently in the process of launching with Riak, and they have chosen to blog about their experiences along the way. First, they wrote about their database evaluation process and why they chose Riak. Then, earlier this week, they wrote about building Riak on OmniOS.
Superfeedr created a Google Reader API replacement and chose to power it with Riak.
For more examples of how companies are using Riak, check out our Users Page.
August 5, 2013
This month, Basho will be at Meetups and other events all over the world – presenting on all things Riak and distributed systems. Here are some of the highlights of where we’ll be in August:
Boston Meetup: Tonight, David Bishop (Lead Systems Administrator at Synacor) will discuss his experience using Riak Enterprise to power a cross-datacenter video metadata product behind some of the biggest ISP’s portals in the business.
DC Meetup: This Meetup will be focused on using different technologies to power mobile apps. It will feature case studies from Rovio and Zope Corporation. This event will take place on August 8th and you can register here.
Los Angeles Meetup: Learn about the new features and updates available with Riak 1.4, including eventually consistent counters. You can register for this August 13th event here.
Berlin Meetup: This eBay Meetup will feature two speakers, including Basho Chief Architect Andy Gross. Andy will speak about the resurgence in interest in both theoretical and applied distributed systems, explore new areas of promising research, and provide practical advice for dealing with systems in our new distributed world. You can register for this August 15th event here.
PuppetConf: Basho will be attending PuppetConf in San Francisco from August 22-23. Come visit our booth and meet our Director of Community, Mark Phillips and our Solutions Engineer, Pavan Venkatesh. Bring any Riak questions and get some great swag.
This is just a few of the events we’ll be at throughout August. For a complete list, check out the Events Page.
July 25, 2013
Hosted Graphite is an open-source, application metrics system that lets you measure, analyze, and visualize large amounts of data about your applications and backend systems, without worrying about setting up your own server and dealing with scaling, backups, or maintenance. They use Riak to store all of their metrics – a time series collection of name-value data.
Hosted Graphite was originally using Whisper, a fixed-size database, which stored their time series data as binaries on disk. However, its focus on simplicity meant that it didn’t offer replication or other helpful features. As their data set grew, they knew they’d need to switch to a system that could more easily distribute their data and scale effectively. Additionally, since there weren’t any plans to hire past the existing two-person ops team, they needed a system that provided always-on availability (as any failures are highly visible to their customers) and operational simplicity.
Based on their criteria, they were able to quickly rule out many other database options. When they came across Riak, it fit all of their requirements and looked operationally friendly, so they decided to try it. They were able to easily get Riak into production and have been live with Riak since June of 2012.
Hosted Graphite runs two Riak clusters and a total of nine nodes. They are currently storing 1.5 billion keys and see 60 GB of growth per day across their nodes. They use both the Bitcask and LevelDB backends.
As Charlie von Metzradt, co-founder of Hosted Graphite, said, “Launching with Riak has helped us sleep at night. We don’t need to worry when a node or two goes down, as we can just deal with it later. For a two person team, this has been invaluable.”
For more information on Hosted Graphite’s experiences with Riak, check out Charlie’s talk from a recent meetup.
You can also visit basho.com to see if Riak is the right fit for your data.
New York, NY– July 24, 2013 – Basho is a proud sponsor and exhibitor of DevCon5 2013, the HTML5 and mobile application developer conference. DevCon5 takes place July 24-25 in New York, NY.
DevCon5 is a conference where both front and back end developers are familiarized with disruptive technologies that enable UX/UI and back end mobile development. While this is Basho’s first year at DevCon, their distributed database, Riak, is already a key tool for backend mobile developers looking to provide “always on” user experiences. Due to Riak’s redundant, fault-tolerant design, Riak also provides a consistently fast mobile user experience that can easily scale and support highly concurrent access. It is currently used to power mobile applications like Voxer, Bump, and Rovio. For more information on how mobile applications and platforms can use Riak, download “Mobile on Riak: A Technical Introduction.”
In addition to sponsoring, Basho UX/UI Lead Designer, Sarah Drasner, will be speaking at DevCon5. Drasner’s talk, “CSS Animations to Tell A Story” will be a deep-dive into creating scalable web graphics for maximum impact, while telling a broader story of emerging tools that allow for less operational complexities and amplified impact. Like Basho’s flagship product Riak, Drasner will discuss how technologies are shifting to meet emerging business requirements, while minimizing immediate operational burdens and enabling ease of scale.
Drasner’s talk begins at 3:30pm ET on Wednesday, July 24th.
July 24, 2013
It is tempting, when considering documentation, to decide that it is “someone else’s problem.” In truth, writing and maintaining documentation is a cross-disciplinary function. Content is paramount, clarity and comprehension of design determines whether the content is accessible, and information architecture will expedite learning…or frustration.
At Basho, we are proud of our documentation. All design, updates, and edits are done in the open and we encourage community participation. Recently, we launched a major refresh to our docs and, in the interest of sharing our learnings with our community, we wanted to describe some of the ideas and principles behind it.
With this recent update, we were particularly interested in a clean and legible design. We wanted a redesign that was easy to read, easy to reference, and easy to reuse.
To that end, we updated the font set to include a serif and a sans serif (Gandhi and Open Sans, respectively). Our design team selected two open source types that worked well together, but also had the best cross-browser and cross-display consistency.
We made the text larger, changed its color to be black on white for higher contrast, and limited the width of the page for ease of reading (à la Matthew Butterick’s suggestions). This focus on legibility allows us to scale content within the same design theme as needed.
As we continue updating Riak, prior documentation remains relevant and accessible. Previously, the Riak version selection was displayed horizontally, with all major releases visible. We added a selection menu that flows vertically and now only indicates the currently-viewed product version.
The navigation has also been updated so the collapse behavior maintains state across pages and links to the Help Page and GitHub repository remain static.
To appeal to our audience of both developers and operators, we now have two distinct tracks of content that are highlighted and organized in the left-hand navigation menu. These tracks are bookended by new introductory content (a slimmed-down version of “The Riak Fast Track”) and conceptual information relevant to both developers and operators.
Furthermore, since developers tend to actually write code, our examples are being refreshed to use code samples, rather than HTTP calls. This will be an ongoing process.
Where Art Meets Science
The decisions about the documentation refresh combined instinct, preference, and empirical data about usage. As the community provides feedback, we will continue to make changes to improve usability.
As with any project of this scope, many members of the Basho team were involved: our engineers who write documentation, the Docs Cabal that managed the process, and the Basho design team that provided dozens of possible designs. This distributed team was able to leverage the best of each others work to produce something beautiful and, most important of all, useful.
July 23, 2013
This week is O’Reilly OSCON, a conference dedicated to all things open source. Basho is a sponsor and Basho engineer, Eric Redmond, will be delivering a presentation entitled “Distributed Patterns In Action“.
Basho first open sourced Riak in 2009. It’s a decision that helped us grow our business, and become a leader in newer, agile enterprise environments. Our participation in the open source community benefits our culture, our development process, and our business.
In honor of OSCON, we thought it important to explore the commercial aspects of our open source decision.
The Business of Open Source
Open source is in the DNA of our company, with both Riak and Riak CS available under the Apache 2 license. (It is worth noting that these products are but a few of our open source contributions, which also include Webmachine and Lager.) To turn this great code into a business, we chose to stay true to our roots as a software company, instead of just selling services. The enterprise versions of Riak and Riak CS offer the entirety of our open source software, with the addition of multi-datacenter replication and monitoring capabilities.
The decision to sell licenses to the enterprise, rather than to rely just on services, makes Basho unique. It allows us to engage with our enterprise customers in the transformation of their application architecture. They can be confident in the software’s availability and in Basho’s commitments to support them – as customers. Enterprises need an alternative to traditional database vendors, but one that can still fit — in license structure, operational management, and process integration — into a traditional organization.
Our licensing model for Riak Enterprise and Riak CS Enterprise lets us balance agility with tradition. Our community helps us develop groundbreaking software, while the enterprise license helps corporate IT and Operations sleep at night.
Open source drives adoption (a concept discussed at length in Stephen O’Grady’s book The New Kingmakers). That means Riak is used across many different industries, powering thousands of applications. That commercial validation — our success in production deployments — is accelerated due to the open source availability.
We remain keenly aware, and tremendously appreciative, that our community (from the individuals to the large organizations) guides Riak and Riak CS updates, and has been crucial to the refinement and forward momentum of this software.
Basho’s success is open source’s success. Our strengths reside both in our team and in our community, as their combined efforts improve our technology and its utilization. We are excited to see what other open source showcases are in view at OSCON 2013.
Portland, OR – July 22, 2013 – Basho is a proud sponsor of O’Reilly OSCON, a conference focused on the entire open source ecosystem. In addition to sponsoring, Basho software engineer, Eric Redmond, will also be speaking at OSCON.
Redmond’s talk, “Distributed Patterns in Action,” will go through a set of distributed data structures and discuss how each works and when should be used. Redmond is a longtime advocate of alternative storage mechanisms (especially the distributed kind) and has co-authored the books, “Seven Databases in Seven Weeks” and “A Little Riak Book.” His talk begins at 11:30am on Thursday, July 25th.
In its fifteenth year, OSCON is known as the primary gathering place for the open source community – bringing together developers, innovators, businesspeople, and investors. It works to bridge partnerships between businesses and the open source community, while also unveiling some of the most groundbreaking open source products and projects. OSCON takes place July 22-26 in Portland, OR.
July 15, 2013
Today, we are sending out our quarterly Riak Community Survey. This survey is to help us better understand how you’re using Riak. By understanding how Riak is being used, we can make more educated decisions about how to improve Riak in the future. We will also anonymize this data and share it with the community to provide a more holistic view of how Riak is being used.
To participate in this survey, simply click here to get started. All survey participants will receive Basho swag and a discount code for RICON West tickets. One lucky participant will be selected to receive a free RICON West ticket.
Thanks for participating in our survey and be sure to grab a RICON West ticket. Early bird prices end August 29th.
Chicago, IL – July 8, 2013 – Throughout the Lambda Jam Conference this week, Basho will be presenting twice about various aspects of Riak, as well as hosting a workshop on Webmachine. Lambda Jam is a conference for functional programmers and features a mix of sessions and workshops. It takes place in Chicago from July 8-10.
John Daily (Technical Evangelist at Basho), will be presenting first on “Distributed Programming with Riak Core and Pipe.” During his talk, he will dive into how Riak Core and Riak Pipe can be used, both within and beyond Basho. His talk begins at 9am on Tuesday, July 9th.
On July 10th at 9:50am, Basho Architect, Steve Vinoski, will be speaking on “Addressing Network Congestion in Riak Clusters.” In this talk, he will discuss an experimental approach to alleviating network congestion effects, such as timeouts and throughput collapse for Riak clusters under extreme load. In addition to exploring network scalability issues, this talk shows how Erlang can seamlessly integrate with non-FP languages.
Finally, Sean Cribbs and Chris Meiklejohn (Software Engineers at Basho) will be hosting a workshop entitled, “Functional Web Applications with Webmachine.” This workshop will provide guidance for understanding and getting started with Webmachine. It will then gradually expose richer HTTP features, while building out an application that is used by browsers and API clients alike. Their workshop begins at 1pm on July 10th.
To see where else Basho will be speaking, please visit our Basho Events Page.