Live data from Hacker News

Ask HN: SQL or NoSQL?

news.ycombinator.com

1–10 of 26 posts

Ask HN: SQL or NoSQL?

#1
Just came across this tweet criticizing the Parler social network for using a relational database:

https://twitter.com/sarahmei/status/1348477224467394560

My understanding was always that for relational data (e.g., social networks) you should use a relational database. Is the person in this tweet correct? If so what is a better option?

Re: Ask HN: SQL or NoSQL?

#2
Unless you've seen their code and their data structures, we don't know the impact on performance of their technical choices. I would say that there is no black and white answer of what type of product needs what type of database -- it all depends on how you design the solution. I'd also venture to say that with so many databases now supporting JSON as a native data type, you can blend relational and non-relational data as needed within a relational DB.

Re: Ask HN: SQL or NoSQL?

#3
It's not about NoSQL vs SQL. Facebook's Tao is still backed by MySQL, so it's not like there's some intrinsic limitation. The issues are number of records examined to return a result, lock contention, sharding, and replication/consistency. NoSQL databases generally trade some of the conveniences of relational to be able to provide stronger properties in these aspects.

The limitations that Sarah Mei identifies as clownpants is using a 32 bit primary key for an identifier for an ephemeral thing. That is again nothing to do with SQL vs NoSQL. It would affect both of them the same way.

Re: Ask HN: SQL or NoSQL?

#4
There is some truth in this tweet but it doesn't mean you should use a nosql document database.

Storing more context in document helps obviously because you don't have to fetch the data many times, it's actually also done in relational databases whenever needed. But you can't store a lot in one document, that doesn't scale nor work.

For example, if someone changes its avatar or want to delete its account, do you want to parse all your social network documents to update an avatar or remove the comments on a tiny subset of them ? If a post is popular, are you going to update its document thousands of times per second ?

In practice you will most likely find a mix of everything. Relational databases, in memory data stores, cache layers, perhaps a few nosql documents database, some big data stuff and a probably some excel sheets.

Re: Ask HN: SQL or NoSQL?

#5
I no longer buy the "use relational databases for relational data, use NOSQL for non-relational data" mentality.

Basically all meaningful data in an application context has relationships. There is no real such thing as "non-relational data"

Instead the question really is do you want a planned, enforced schema or an unplanned, freeform one.

Use a SQL database for the former.

Take a long look in a mirror and question the decisions that made you the way you are if the latter.

Re: Ask HN: SQL or NoSQL?

#6
I think it always originates from business analysis requirements. Do you have some analysis that could be difficult to perform if using X? If it is then maybe switch to Y, or find a balance, or even build duplicates.

Re: Ask HN: SQL or NoSQL?

#8
Don't worry too much about this tweet, my guess is that the author wanted to express a strong opinion to provoke a reaction form a certain audience.

Once you reach a large scale, relational databases start being a problem for availability and replication of data across different availability zones. Operations become complicated (you have replication chains, master/slave setups, etc.)

If your data is relatively simple and doesn't require a lot of relations and foreign keys, then something like Cassandra can save a lot of headaches.

Btw, a common trick to make a relational database perform at scale by limiting joins is to "flatten data", i.e. replicate data across different tables to avoid joining them.

Finally, don't let yourself be fooled by anyone who claims they know "the better option." There is no better option. There is only a better option for a particular use case you're looking at, given the specific constraints at hands. That's what engineering is about, including software engineering.

If you want to learn more about designing storage systems by constraints, I recommend that you read the 2007 Dynamo paper from Amazon, and in particular section 2.3 "Design Considerations". Below is a link, you can easily find a PDF online if you need.

https://www.allthingsdistributed.com/2007/10/amazons_dynamo....

Re: Ask HN: SQL or NoSQL?

#9
> My understanding was always that for relational data (e.g., social networks) you should use a relational database.

I thought you were supposed to use a graph database for that, like dgraph. Do I remember incorrectly?

> Dgraph is a horizontally scalable and distributed GraphQL database with a graph backend.

---

Edit: found the source... According to https://www.infoworld.com/article/3251829/why-you-should-use...:

"However, as with any popular technology, there can be a tendency to apply graph databases to every problem. It’s important to make sure that you have a use case that is a good fit. For example, graphs are often applied to problem domains like:

- Social networks

- Recommendation and personalization

- Customer 360, including entity resolution (correlating user data from multiple sources)

- Fraud detection

- Asset management"

Re: Ask HN: SQL or NoSQL?

#10
All ways use SQL

NoSQL is for incompetent people who can't figure out how to convert a JSON request to a table structure. They just put the entire JSON as it is in a DB and call it NOSQL.

Anyone using NoSQL for anything is either lying or clueless.

Post reply on HN