News for hackers. Stuff that matters.
Re:SQL is 43 years old – Here’s why we still use it today by davnicwil on Tuesday May 02, 2017 @07:19AM (#14245469)
Just for fun: does anyone have any stories about initially using a SQL database for a project, later hitting problems, then switching to (or augmenting with) a NoSQL solution that solved those problems?
Re:SQL is 43 years old – Here’s why we still use it today by sergiosgc on Tuesday May 02, 2017 @07:32AM (#14245507)
I've reached a point where my default design is relational database augmented with memcache/redis. The relational DB is the authoritative source of truth, redis absorbs all (most) reads and memcache is, well a distributed cache. Writes go to both redis and relational. Redis data can always be rebuilt, and is regularly rebuilt, from relational data.

At project onset, usually only redis or memcache are in use.

It's a model that has served me well, apart from bugs that cause divergence between redis and relational. These are usually the class of bugs that would corrupt data were I relying on redis alone, so I just think of them as a lesser evil.

There's an obvious bottleneck on writes to the relational DB but I've so far managed to keep from hitting that ceiling.

Re:SQL is 43 years old – Here’s why we still use it today by scarface74 on Tuesday May 02, 2017 @08:42AM (#14245858)
I've reached a point where my default design is relational database augmented with memcache/redis. The relational DB is the authoritative source of truth, redis absorbs all (most) reads and memcache is, well a distributed cache. Writes go to both redis and relational. Redis data can always be rebuilt, and is regularly rebuilt, from relational data.

I'm really becoming a big fan of CQRS/event sourcing where we have two read models - one NoSql for live data and one relational for BI/Reporting. Events are stored separately in JSON because that's how they come in anyway through the API.

Re:SQL is 43 years old – Here’s why we still use it today by remotehack on Tuesday May 02, 2017 @10:27PM (#14252558)
Wow. Let the maintenance begin.
Re:SQL is 43 years old – Here’s why we still use it today by scarface74 on Wednesday May 03, 2017 @09:25AM (#14255424)
CQRS is not rocket science. In any case, your schema for your reporting database is usually different from your online database.
Re:SQL is 43 years old – Here’s why we still use it today by Kiro on Tuesday May 02, 2017 @08:20AM (#14245733)
Kind of. I started building my game using SQL but realized everything became so much easier if I didn't have to follow a schema. For example I like to add arbitrary properties to the player objects all the time. With MongoDB it's a no-brainer. I just add the property and save.
Re:SQL is 43 years old – Here’s why we still use it today by elmigranto on Tuesday May 02, 2017 @08:35AM (#14245816)
> no schema

Do you read them back? Does your code expect property "X" to be on a "Player" object? Do you put a check everywhere for when it doesn't? Do you have default value for objects that were created before new property was added?

All that work could've been done by your database (which is probably has some kind of JSON implementation anyways), but somehow it's a "no-brainer" to implement data consistency at app-level. Okay.

Re:SQL is 43 years old – Here’s why we still use it today by scarface74 on Tuesday May 02, 2017 @08:44AM (#14245881)
Does your code expect property "X" to be on a "Player" object? Do you put a check everywhere for when it doesn't? Do you have default value for objects that were created before new property was added

Why would you put checks everywhere a properly written code base would have one module/service that handles the player object and every consumer would use that one module.

Re:SQL is 43 years old – Here’s why we still use it today by aidos on Tuesday May 02, 2017 @09:03AM (#14245982)
There have to be some checks, somewhere. Even though it's limited to one module, you can get temporal inconsistencies.

e.g. you add a new field and an application level default, then later that default is changed. Now there's no notion of which default the docs that never had the property should be using. Sure, you just need to patch the old docs to set the property where it's missing. But the GPs point was that by not keeping a consistent schema you end up moving the definition of the data into the application, and you need to be very aware of the trade-off.

Personally I'm really happy using postgres and dropping into jsonb when it's the correct model to use. It's the best of both worlds as far as I'm concerned. I've built and worked on systems using nosql solutions that have been migrated back to sql and the data inconsistencies we found have made me very wary of having a primary datastore that doesn't enforce strict constraints.

Though, everybody's use case is different.

Re:SQL is 43 years old – Here’s why we still use it today by scarface74 on Tuesday May 02, 2017 @09:19AM (#14246081)
But the GPs point was that by not keeping a consistent schema you end up moving the definition of the data into the application, and you need to be very aware of the trade-off.

Why wouldn't the defaults be in the application? Why wouldn't it be treated like any other piece of business logic in code that should be unit tested?

That being said, I only caught the NoSQL religion about six months ago when I started using Mongo. But SQL Server 2016 has such great support for JSON natively, as long as I'm spending other people's money, I prefer having the best of both worlds.

Re:SQL is 43 years old – Here’s why we still use it today by elmigranto on Tuesday May 02, 2017 @10:00AM (#14246351)
> Why wouldn't the defaults be in the application? Why wouldn't it be treated like any other piece of business logic in code that should be unit tested?

How about we check our data in the place where it lives given how very robust and mature products that do that were already written, tested, and used in production by literally thousands of people for decades.

Re:SQL is 43 years old – Here’s why we still use it today by scarface74 on Tuesday May 02, 2017 @01:31PM (#14248497)
How about we check our data in the place where it lives given how very robust and mature products that do that were already written, tested, and used in production by literally thousands of people for decades.

So by "checking data" can we check all of the business constraints?

Re:SQL is 43 years old – Here’s why we still use it today by elmigranto on Tuesday May 02, 2017 @01:46PM (#14248675)
Yes. If you really want to.

Definetly stuff like presence of fields and their basic sanity (string not being empty or within a certain length), date intervals, uniqueness of certain fields or combinations, etc.

You can go as far as you want, really; but like with most cases, when there's a range of possibilities, both extremes are probably a wrong answer.

Re:SQL is 43 years old – Here’s why we still use it today by Kiro on Tuesday May 02, 2017 @09:05AM (#14245995)
Yes, I read them back as a JS object in whole on login. A few things are mandatory (hp, position) but most are optional and are only checked where needed.

    if (player.hasSomeProp) {
      doStuff(player);
    }
With your suggestion I would have a table with 200 fields and would probably have to add a lot of related tables since some of the props are arrays, objects etc. I also would lose the ability to just load the player as is (player = documentFromDB).

With "no-brainer" I mean it doesn't take any effort when developing since the representation of the player object in runtime is exactly the same as it's stored in the database.

Re:SQL is 43 years old – Here’s why we still use it today by elmigranto on Tuesday May 02, 2017 @09:43AM (#14246226)
I wasn't really suggesting anything, but if I were, Postgres and its binary JSON (`jsonb`) would be there alongside with full and easy indexing support and other SQL nicities like constraints, triggers, transactions, custom procedures, etc.

There are also excellent out-of-the-box support for arrays, enums, custom types, and JS procedures if you so desire. All that comes with consistent syntax, great aggregation functions, JOINs; and all those 43 years of advancement mentioned in general.

Read the docs, you'll be amazed with what you're missing :)

General overview https://www.postgresql.org/docs/current/static/tutorial.html

JSON support specifically https://www.postgresql.org/docs/current/static/datatype-json...

Re:SQL is 43 years old – Here’s why we still use it today by pythonaut_16 on Tuesday May 02, 2017 @09:27AM (#14246137)
I don't know anything about your game but I wonder if you could use SQLite to a similar effect.

If you just want things as JS objects, you could have a Player table with a column for playerID and a column for the JSON string.

I'm not saying you shouldn't use Mongo/NoSQL, I just think SQLite is an interesting potential choice. (e.g. https://sqlite.org/appfileformat.html)

Re:SQL is 43 years old – Here’s why we still use it today by 72deluxe on Tuesday May 02, 2017 @10:11AM (#14246427)
Couldn't you have designed your schema to have a playerProperties table with a playerId column, a key column and a value column?

That'd be forever extensible and if you made the primary key a combination of playerId and key, you'd offload duplicate handling to the database.

Seems simple to me.

Re:SQL is 43 years old – Here’s why we still use it today by combatentropy on Wednesday May 03, 2017 @03:05AM (#14253624)
That's called EAV (Entity Attribute Value, https://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80...).

I have done it before, once. While some folks will tell you it's just wrong, like NoSQL I think it's sometimes the best fit, even for the entire life of the app.

For 99% of things, though, I use SQL tables, normalized to the Third Normal Form, foreign keys, the whole shebang.

Re:SQL is 43 years old – Here’s why we still use it today by pinouchon on Tuesday May 02, 2017 @08:00AM (#14245632)
Most of the stories I have heard are from people choosing a noSQL store for the wrong reasons. They end up going back to a relational DB because now they see the value of ACID. The typical case is Mongo => Postgres/Redshift.
Re:SQL is 43 years old – Here’s why we still use it today by fs111 on Tuesday May 02, 2017 @07:28AM (#14245495)
I think most people in that group start out with a normalized schema in a SQL db and end up in a highly denormalized or even key/value style setup in said DB. Technically it is still a SQL database, but not used in that way.
Re:SQL is 43 years old – Here’s why we still use it today by jerven on Tuesday May 02, 2017 @07:36AM (#14245524)
public UniProt.org went from SQL normalized -> SQL primary key/blob to proper K/V (BDBje) to custom K/V in the space of ten years.

However, data production is still a mix of batch and sql systems.

Re:SQL is 43 years old – Here’s why we still use it today by zzzcpan on Tuesday May 02, 2017 @10:08AM (#14246401)
Switching a project from SQL to NoSQL is usually too expensive. Traditional relational databases lack a lot of necessary constraints to even have architectures necessary to make the switch to a distributed database, it can only happen with a complete redesign of everything. I think it's more common for those who had problems with SQL databases to drop them for their next projects and move on. For example, I consider a highly-available multi-site distributed database as a minimum viable database and haven't used an RDBMS in like a decade.
Re:SQL is 43 years old – Here’s why we still use it today by 33degrees on Tuesday May 02, 2017 @09:05AM (#14245996)
If you consider ElasticSearch a NoSQL solution, then yes, many stories. A properly normalized database can be very slow to search, and throwing ElasticSearch in front of it is a very common solution.
Re:SQL is 43 years old – Here’s why we still use it today by prashnts on Tuesday May 02, 2017 @10:17AM (#14246491)
We used to use Postgres for almost everything, including full-text search.

Later when we needed a bit more control over search, we started using Elasticsearch. The way we do it now is to perform joins and get a nice serialized object with all the possible search/filter/sort fields, and put it in ES. All the data still remains in postgres, though.

Re:SQL is 43 years old – Here’s why we still use it today by danso on Tuesday May 02, 2017 @08:37AM (#14245833)
I had assumed Facebook started off with MySQL and now is NoSQL but that was just ignorant of me:

Zuckerberg may have had to rely on a typical LAMP stack but FB's newer user-facing features still use SQL. For example, the Timeline feature released in 2012 was built on MySQL/InnoDB: https://www.facebook.com/note.php?note_id=10150468255628920

And last year Facebook released MyRocks, which is a space/write optimized replacement for InnoDB, and is being used for their "user database tier" https://code.facebook.com/posts/190251048047090/myrocks-a-sp...

I guess the things I've read about FB using NoSQL [1] is for other parts of their infrastructure, particularly Messages. It sounds like they had considered using MySQL, even though Cassandra was built for the Inbox feature. They ended up building a new system for Messages [2].

Now that I've spent a little time in that rabbit hole, it looks like one answer to your question is Facebook's Inbox Search, which used MySQL originally to store inbox data (7TB for over 100M users, which seems laughably small with respect to Facebook's scale today):

http://docs.datastax.com/en/articles/cassandra/cassandrathen...

> Before launching the Inbox Search application we had to index 7TB of inbox data for over 100M users, then stored in our MySQL[1] infrastructure, and load it into the Cassandra system. The whole process involved running Map/Reduce[7] jobs against the MySQL data files, indexing them and then storing the reverse-index in Cassandra. The M/R process actually behaves as the client of Cassandra. We exposed some background channels for the M/R process to aggregate the reverse index per user and send over the serialized data over to the Cassandra instance, to avoid the serialization/deserialization overhead. This way the Cassandra instance is only bottlenecked by network bandwidth.

The acknowledgments section makes it more clear that the MySQL data was indeed migrated over to Cassandra:

> Cassandra system has benefited greatly from feedback from many individuals within Facebook. In addition we thank Karthik Ranganathan who indexed all the existing data in MySQL and moved it into Cassandra for our first production deployment.

[1] https://news.ycombinator.com/item?id=7891316

[2] https://www.facebook.com/notes/facebook-engineering/the-unde...

Re:SQL is 43 years old – Here’s why we still use it today by johnchristopher on Tuesday May 02, 2017 @07:32AM (#14245508)
I suppose they'd look first into MySQL's new JSON support. (Or other SQL database that have some kind of JSON support)
Re:SQL is 43 years old – Here’s why we still use it today by Klathmon on Tuesday May 02, 2017 @09:26AM (#14246129)
PostgreSQL has fantastic JSON support and i've used it a few times.

Not only is it fairly fast, but it lets us tie JSON blobs that really don't need schema enforcement to be still tagged with the rest of the data and laid out relationally to still allow complex queries.

Re:SQL is 43 years old – Here’s why we still use it today by kalleboo on Tuesday May 02, 2017 @10:08AM (#14246403)
Does using memcache for caching count as "augumenting with a NoSQL solution"? Because that's pretty popular...
Re:SQL is 43 years old – Here’s why we still use it today by FLUX-YOU on Tuesday May 02, 2017 @08:32AM (#14245797)
Logging
Re:SQL is 43 years old – Here’s why we still use it today by lr4444lr on Tuesday May 02, 2017 @07:52AM (#14245589)
Yeah, I use MongoDB whenever my tables get too big. It's web scale! </s>