News for hackers. Stuff that matters.
Re:We saved $50k/year with a Go microservice coded in a hack... by owenmarshall on Tuesday April 10, 2018 @08:38PM (#16807059)
> Stuff like this is bread and butter SQL.

Ten or fifteen years ago, sure - a DBA would look at a query plan and figure out how to do it properly. Worse case you'd slap a materialized view in and query that.

But this is 2018! Programmers don't want to treat the database as anything but one big key value store ;)

Re:We saved $50k/year with a Go microservice coded in a hack... by Matheus28 on Tuesday April 10, 2018 @08:57PM (#16807159)
If you aren't implementing your own tabular database on top of your existing tabular database, you aren't 2018 enough :)
Re:We saved $50k/year with a Go microservice coded in a hack... by mathgladiator on Tuesday April 10, 2018 @10:10PM (#16807502)
I'm changing the game by code generating a tabular database on top of an eventualy consistent store. 2020 here we come!!!
Re:We saved $50k/year with a Go microservice coded in a hack... by elvinyung on Tuesday April 10, 2018 @11:36PM (#16807835)
Rows by any other name would smell as sweet...
Re:We saved $50k/year with a Go microservice coded in a hack... by mgkimsal on Tuesday April 10, 2018 @10:47PM (#16807645)
better make sure it's all immutable too.
Re:We saved $50k/year with a Go microservice coded in a hack... by LoSboccacc on Wednesday April 11, 2018 @03:47AM (#16808909)
oh boy do I have news for you https://www.cockroachlabs.com/
Re:We saved $50k/year with a Go microservice coded in a hack... by elvinyung on Wednesday April 11, 2018 @05:38AM (#16809445)
not an eventually consistent store though.
Re:We saved $50k/year with a Go microservice coded in a hack... by cookiecaper on Tuesday April 10, 2018 @08:51PM (#16807135)
Yeah, sadly, this is not too much of an exaggeration. I've worked on teams that insisted they needed DynamoDB, because, well, Dynamo is for "Big Data", and they certainly wouldn't work somewhere that had "Small Data"! Replace the buzzwords/products as applicable; you could actually probably just scramble them and it'd work just as well, since someone out there thinks "RabbitMQ means Web Scale", etc.

SQL databases are amazing, robust examples of engineering. They are your friends and they're the appropriate choice for the vast majority of software. They are not outmoded or passe. Though I acknowledge there is a separate use case for K-V stores, I almost want to make policy preventing their use just because I know so many developers will abuse them badly and then stare back at you blankly during the semi-annual massive downtime event, muttering something like "Well, it's based on research at Google, so I'm sure there's a way to recover the data..."

Re:We saved $50k/year with a Go microservice coded in a hack... by MrMorden on Tuesday April 10, 2018 @10:33PM (#16807591)
Every fool knows that MongoDB is web scale. (Not as web scale as /dev/null, but MongoDB has a better logo.)
Re:We saved $50k/year with a Go microservice coded in a hack... by reificator on Wednesday April 11, 2018 @03:53AM (#16808935)
I disagree. /dev/null's logo is way cooler.

https://www.nasa.gov/sites/default/files/cygx1_ill.jpg

Re:We saved $50k/year with a Go microservice coded in a hack... by toddBarkus on Tuesday April 10, 2018 @09:01PM (#16807176)
I think this is a case for the return of the traditional "sysadmin" as "devops"/"SRE" is now the role of unblocking deploying a solution instead of questioning it's complexity/fitness.
Re:We saved $50k/year with a Go microservice coded in a hack... by cookiecaper on Tuesday April 10, 2018 @09:33PM (#16807311)
While I agree, I also think that overt gating and approval processes create a high tension dynamic that frequently breaks down, whether it's ops v. dev, security v. dev, or others. It's easy for people to get their pride wounded, and they end up encouraged to find workarounds to the process. The simple answers to this are pretty much imaginary, unfortunately.
Re:We saved $50k/year with a Go microservice coded in a hack... by toddBarkus on Wednesday April 11, 2018 @08:08AM (#16810272)
Sure, of course. I was hoping to point out that there's an increasingly overlooked value in having someone question complexity. The "no, you don't need React" of the frontend dev or the "our data is actually relational" of the back end dev.
Re:We saved $50k/year with a Go microservice coded in a hack... by rbranson on Tuesday April 10, 2018 @11:27PM (#16807801)
If your “SRE” team is only “unblocking deploying a solution” then I’m sad to say they are an operations team who has rebranded themselves to appear more relevant.
Re:We saved $50k/year with a Go microservice coded in a hack... by toddBarkus on Wednesday April 11, 2018 @08:05AM (#16810260)
That's most "SRE" -- it's a title arms race in that field between the underqualified and those that wish to convey they know how to do more than write system scripts in DSLs
Re:We saved $50k/year with a Go microservice coded in a hack... by EGreg on Tuesday April 10, 2018 @10:10PM (#16807508)
Question, though...

If your columns have types, how can you encrypt them using custom keys for each one? Is it possible?

I want the keys to reside on the client and search for encrypted data. Basically single row lookups at a time.

Re:We saved $50k/year with a Go microservice coded in a hack... by pandapunchpower on Tuesday April 10, 2018 @11:35PM (#16807834)
The column type would have to be the type of the encrypted value. The type of the unencrypted data could not be enforced by the DB and you would have to rely on code doing the correct thing.

I am however extremely wary of doing it that way. I don't know your requirements of course.

Re:We saved $50k/year with a Go microservice coded in a hack... by EGreg on Wednesday April 11, 2018 @10:03AM (#16811147)
Here is the thing - encrypted stuff is just a weird encoded string. So I can’t really use columns normally.

What I really need is just a huge table with two fields: “token”, “content”

And the token is basically the primary key but encrypted with whatever encryption.

You could even do foreign keys this way.

Hmm I suddenly have an idea. What about a layer above the database that basically enforces foreign keys and joins in this way to support end to end encryption? The content would reference ENCRYPTED foreign keys. Only clients would decrypt stuff.

Re:We saved $50k/year with a Go microservice coded in a hack... by pandapunchpower on Wednesday April 11, 2018 @10:40PM (#16817573)
>What I really need is just a huge table with two fields: “token”, “content”

Sounds more like a key value store and less like a relational database. Although you can store key value data in a relational db of course, there may be a better tool for the job.

Re:We saved $50k/year with a Go microservice coded in a hack... by JoachimSchipper on Thursday April 12, 2018 @02:00PM (#16823331)
You'll be interested in CryptDB.
Re:We saved $50k/year with a Go microservice coded in a hack... by LgWoodenBadger on Wednesday April 11, 2018 @11:25AM (#16812076)
Are you sure you aren't better off searching for hashed data? The only thing it doesn't really support is non-exact matches.
Re:We saved $50k/year with a Go microservice coded in a hack... by nurettin on Tuesday April 10, 2018 @11:51PM (#16807881)
Also, how do you index that?
Re:We saved $50k/year with a Go microservice coded in a hack... by Regardsyjc on Tuesday April 10, 2018 @09:50PM (#16807400)
Do you have any recommendations for resources to learn best database practices? I'm currently designing my first database and I'm not sure what information is worth storing (like calculations) and how to choose which data to group in tables.
Re:We saved $50k/year with a Go microservice coded in a hack... by fnord123 on Wednesday April 11, 2018 @02:57AM (#16808702)
SQL Antipatterns is good as another commenter recommended. But my favourite book on the topic is Markus Winand's SQL Performance Explained. Most of it is online here: https://use-the-index-luke.com/ but I recommend buying it since it's tiny and worth its weight in gold.

It's short so you actually read it and possibly reread it. It's to the point. It has pretty pictures. And it had directly applicable advice.

Re:We saved $50k/year with a Go microservice coded in a hack... by jmts on Wednesday April 11, 2018 @09:12AM (#16810739)
I'm going to go out on a limb and suggest you start writing the application without a database first.

My early education on databases always seemed to follow a "how do we make a database do this?" rationale rather than "what data do we need to store to support these features?", which I think leads to a software design that is too strongly coupled with the database. Software modules end up dependent on database features, or table structure, and refactoring or switching data stores becomes more costly.

Instead, start with a simple in-memory data store - a list of objects with some interface for accessing them, will probably your starting point. Add some basic serialisation/deserialisation features (CSV, JSON, etc) when you get past initial testing and require some persistent data. Then, once you have your API in place and your software design is stabilising, you should be able to map that data to a database fairly easily:

* The primary structure maps to your main table

* Child structures become additional tables, with foreign keys

* Data used to lookup records can be indexed for better performance

Beyond that, you should profile/benchmark your application to find what needs to be optimised, and then investigate whether your software design or your data store should be doing the optimisation.

Let your software's features influence the design of your database. Don't let the database's features influence the design of your software.

Re:We saved $50k/year with a Go microservice coded in a hack... by jonah on Tuesday April 10, 2018 @11:51PM (#16807883)
I read SQL Antipatterns[0] - Avoiding the Pitfalls of Database Programming by Bill Karwin a while ago and really liked it.

[0] https://pragprog.com/book/bksqla/sql-antipatterns

Re:We saved $50k/year with a Go microservice coded in a hack... by matte_black on Tuesday April 10, 2018 @11:48PM (#16807874)
Ok, first you need to decide: is this going to be a purely transactional database (for business processes) or do you also plan to do data analysis straight inside this database (meaning you won’t be extracting, transforming and loading data into another database and analyzing it there).

If it’s transactional, I recommend keeping calculations only if you need to access summarized data frequently. For example, if you are tracking inventory by storing the history of transactions that occur into and out of inventory, it’s trivial to find out how much of each item you have in stock at any point in time by doing a sum of the change in quantities for each item type up to that point.

If you were usually interested in the “current” count, it would be expensive to perform this sum every time, so instead you could keep a separate table for calculating the running total of inventory per item and referring to that. Keep this table up to date through the use of triggers on insert events (Note that your log of inventory transactions would thus be an immutable stream of events)

An example of something not worth storing is derived data that is a combination of separate columns in a table. For most queries it’s probably trivial to be lazy and wait to perform such a calculation until you actually need it. If you still want to have a ready made “table” that has all the computations you want already entered as columns for easy querying, use a view. If you find yourself making liberal use of views, you’re on the right track.

If you are using a separate data warehouse for data analysis, then precompute and denormalize as much as you can.

*Disclaimer: most of what I’m talking about is from a Postgres perspective.

Re:We saved $50k/year with a Go microservice coded in a hack... by dugmartin on Wednesday April 11, 2018 @07:04AM (#16809840)
I’d suggest learning the fundamental normal forms - once you understand them database design is very straightforward.

https://en.wikipedia.org/wiki/Database_normalization

Re:We saved $50k/year with a Go microservice coded in a hack... by jehlakj on Tuesday April 10, 2018 @11:10PM (#16807733)
You can thank full stack developers for that
Re:We saved $50k/year with a Go microservice coded in a hack... by flukus on Tuesday April 10, 2018 @11:31PM (#16807823)
If they don't know how to look at a query plan and craft a solution can you really call them full stack?
Re:We saved $50k/year with a Go microservice coded in a hack... by vishnugupta on Tuesday April 10, 2018 @11:45PM (#16807866)
The stack has to bottom our somewhere and it's usually at the application code
Re:We saved $50k/year with a Go microservice coded in a hack... by matte_black on Wednesday April 11, 2018 @12:04AM (#16807941)
If that’s where they bottom out they should be called “mid stack” rather than full stack.

If you are claiming to be full stack you better be prepared to go all the way.

Re:We saved $50k/year with a Go microservice coded in a hack... by zaarn on Wednesday April 11, 2018 @03:38AM (#16808868)
I would describe myself full stack under that definition. Most "full stack" people I know that sit in my Uni courses have mostly learned Java EE + Oracle DB or Javascript + /dev/null^w^w MongoDB. Most of them would probably not be able to construct a relational database or libc from scratch.

Granted, such knowledge isn't immediately useful since it's something I or anyone is likely to do but it grants insight into systems. I know roughly how a query optimizer does and what it can, and more importantly, can't do.

When you know a system you can optimize for it. When you don't know a system you can only follow someone else's advice on how to optimize for it.

Re:We saved $50k/year with a Go microservice coded in a hack... by majewsky on Wednesday April 11, 2018 @05:26AM (#16809367)
> /dev/null^w^w MongoDB

Nitpick: That's actually either three ^w or just one ^w, depending on how your WORDCHARS is set up. :)

Re:We saved $50k/year with a Go microservice coded in a hack... by zaarn on Wednesday April 11, 2018 @05:45AM (#16809487)
I'm sadly not that much of a Vim expert, Hackernews lacks formatting for a strikethrough and I wasn't sure how a ~~/dev/null~~ would be interpreted.
Re:We saved $50k/year with a Go microservice coded in a hack... by adrianN on Wednesday April 11, 2018 @01:19AM (#16808268)
How much quantum mechanics do you really need to know to code the next Uber for hamsters?
Re:We saved $50k/year with a Go microservice coded in a hack... by flukus on Wednesday April 11, 2018 @01:50AM (#16808383)
Isn't the current quest in quantum mechanics (to find a grand unified theory) to find an abstraction that does leak? At the moment it's too self contained and doesn't explain anything about the macroscopic world.

In any case, having a basic understanding of the next level up (the electron) has proved quite useful to my career, otherwise I wouldn't know how turning things off then on again affects the machines I'm working with.

Re:We saved $50k/year with a Go microservice coded in a hack... by chiefalchemist on Tuesday April 10, 2018 @11:26PM (#16807797)
Them, or the manager that hired them? If no one up the chain brings on a DBA what are they supposed to do? I hear ya. But this is as much a symptom of naive (and budget stretched) leadership as it is of the hands on deck.
Re:We saved $50k/year with a Go microservice coded in a hack... by olalonde on Wednesday April 11, 2018 @03:48AM (#16808911)
Your solution costs 150K$/year while theirs took a weekend and saves 50K$/year...
Re:We saved $50k/year with a Go microservice coded in a hack... by chiefalchemist on Wednesday April 11, 2018 @05:32AM (#16809392)
Allow me to clarify.

1) It took a weekend to complete. The friction was building for far longer. There's a cost to that, esp if it effects customer satisfaction and retention. They didn't refactor for fun, did they :) How many dev teams aren't so lucky? Is this article a no choice outlier, or a best practice?

2) My comment wasn't directed at the article but on another comment that blamed the developers. These problems should be owned by ownership / leadership / management more and engineers less.

3) That said, hire a DBA? I don't think that's necessary.

Re:We saved $50k/year with a Go microservice coded in a hack... by collyw on Wednesday April 11, 2018 @09:43AM (#16810957)
I call myself full stack and I can tune a database. decent database design comes first though.