News for hackers. Stuff that matters.
Re:We saved $50k/year with a Go microservice coded in a hack... by nstart on Tuesday April 10, 2018 @11:31PM (#16807824)
Oh gosh this pattern. The first time I encountered it was in my first job where we used Magento. Super flexible. Also super slow. Does anyone have any advice how to make a db design like this work faster? Generally I thought when data is arranged like this it might be a prime candidate for document based storage. But I'm no dba so I have no idea if that would be correct.
Re:We saved $50k/year with a Go microservice coded in a hack... by matte_black on Tuesday April 10, 2018 @11:54PM (#16807898)
If you are using Postgres, the JSONB datatype will let you do exactly this while still using the full power of SQL. Simply create a column where you keep a JSON object full of random user properties, if flexibility is what you want. You can even index properties.
Re:We saved $50k/year with a Go microservice coded in a hack... by mhd on Wednesday April 11, 2018 @03:42AM (#16808883)
Or just create ad hoc tables with user fields. Quite often it's not that a customer has n different fields for n entities, but a few that apply to the majority (like internal ERP ids, classifcation etc.). Put them in a few tables, index them, join them. If you don't want to parse internal DB descriptors, create a set of "schema" tables to build queries from.
Re:We saved $50k/year with a Go microservice coded in a hack... by icebraining on Wednesday April 11, 2018 @12:57AM (#16808160)
The question is whether it can be stored like this while allowing for fast queries. For example, unless it changed recently, Postgres doesn't calculate statistics to help the query planner on jsonb fields.
Re:We saved $50k/year with a Go microservice coded in a hack... by zaarn on Wednesday April 11, 2018 @03:44AM (#16808891)
JSONB columns should behave just like any datatype with a GIN index in the recent releases, to my knowledge.

Still, a JSON column will arguably be faster than a pure KV table since you can more efficiently query it, especially any non-JSON columns.

Re:We saved $50k/year with a Go microservice coded in a hack... by ptman on Wednesday April 11, 2018 @05:08AM (#16809296)
IIRC JSONB still has problem with index statistics

So values in JSONB columns can be indexed nicely, but the statistics can be much worse than for non-JSONB columns, which can lead the query planner astray.

Re:We saved $50k/year with a Go microservice coded in a hack... by NickNameNick on Wednesday April 11, 2018 @05:42AM (#16809467)
Postgres will let you create an index on an expression into the JSON column, so querying should still be very quick.
Re:We saved $50k/year with a Go microservice coded in a hack... by matte_black on Wednesday April 11, 2018 @01:21AM (#16808273)
The answer would make a great blog post.
Re:We saved $50k/year with a Go microservice coded in a hack... by bitexploder on Tuesday April 10, 2018 @11:58PM (#16807916)
This just isn't that hard. They don't have that much data. It is really late for me, but, put it all in memory and figure it out. These just aren't hard problems. DBAs have been solving performance issues for decades with a clever index on the right column for 30+ years. Sorry if this is get off my lawn-ish, but I have been on too many projects where I made a DB index and solved a major bottleneck. Too many new developers are ignorant to the nuance of RDBMS tuning. I am not even a DBA.
Re:We saved $50k/year with a Go microservice coded in a hack... by collyw on Wednesday April 11, 2018 @09:49AM (#16811008)
I am not a DBA, but I could see this crap when the NoSQL hype took off.

"Relational databases don't scale"

Well they worked fine for decades before Mongo's marketing claimed so.

Re:We saved $50k/year with a Go microservice coded in a hack... by thecatspaw on Wednesday April 11, 2018 @01:34AM (#16808333)
> Does anyone have any advice how to make a db design like this work faster?

Normalize it properly. If this is not possible, ensure that both the userid and the property are indexed

Re:We saved $50k/year with a Go microservice coded in a hack... by bpicolo on Wednesday April 11, 2018 @08:52AM (#16810572)
If what you actually want is data arranged like such, Datomic is probably a prime candidate

https://www.datomic.com/