Relational vs. NoSQL Databases for API Traffic
Take a look at the priorities and pros and cons of SQL and NoSQL when it comes to dealing with API traffic.
Join the DZone community and get the full member experience.Join For Free
api consumption drives the importance of api traffic. without insight into how your apis are being consumed, you’re unable to get the analytics for your customers and api usage.
api traffic data has a few characteristics; high frequency, payload sizes, data structure, tables, volume, and objects. persisting api traffic is important because most services have some sort of rate-limiting and different billing tiers for customers based on their usage. there is usually a threshold for alerting and scaling, so if someone is using more api calls than they should, you can partition them. you also want to be able to provide analytics to your internal organization for the different apis/resources you are exposing. if your customers are exposing an api, it is a good bet that they are integrating with other services as well, allowing them to slice and dice their data with the data they are consuming from your product.
there are differences in typical api request payloads and response payloads. the request data vs. response data can change what your persistent strategy needs to be. with request payloads, you usually have moderate-to-large payload sizes. about 80% of api requests are get requests, and post requests can also be large. the response payloads are also typically large in size. the data structures are indeterministic, meaning when you are trying to run analytics on the data the table can be large and slicing and dicing the data responses can be variable.
establishing that persisting the data is the best option, most will look to some sql database, considering that they are most likely already using one. the question is whether a nosql database should be considered. sql, being more than 40 years old, is the primary interface for rdmbs and, having commercial and open-source implementations, it is a strong consideration.
nosql, on the other hand, has existed since the 1960s and was the primary storage mechanism before sql gained popularity. it has gained more traction in last 10 years.
with the comparison of the two technologies below, the main factors in the decision-making process are data growth, online versus archived data, search filter flexibility, search performance, and clustering and sharding. when deciding what the best is for you, consider the measure of your current inbound api traffic, the data-retention policy, estimated data growth, and if your customers need heavy slicing and dicing.
|relational model with data organized in a tabular structure.||differenent model — document, graph, key value.|
|pre-defined schema definition.||dynamic schema definition.|
|typically vertically scalable — higher cost vms.||
horizontally scalable — lower cost vms.
|powerful and standardized query interface.||query interface varies by provider.|
|most implementations are acid-compliant.||follows cap (consistency, availability, partitioning) .|
you can use a sql datastore for:
- manageable data sizes.
- low time period or size-based retention policies.
- low usage frequency.
- lightweight analytics.
- query interface needs to be standardized.
you can use a nosql for when:
- scale and volume are important.
- deep analytics are required.
- fast queries are paramount.
- you can live with a non-standard query interface
Published at DZone with permission of Vineet Joshi. See the original article here.
Opinions expressed by DZone contributors are their own.