Skip to content

Instantly share code, notes, and snippets.

View nate-gehringer's full-sized avatar

Nate Gehringer nate-gehringer

View GitHub Profile

Some Musings on Guard Clauses and Fault Tolerance

“Or: How I Learned to Stop Worrying and Love the Exception”

Background

I used to work at a healthcare technology company that was headed on the tech side by a database nut. The data model was both sprawling and very normalized (by that, I mean gnarly). We worked mainly in the exciting realm of medical billing and patient demographic data – particularly involving data with errors and omissions needing correction. Concordantly (😏), a large proportion of the relationships between tables were represented with nullable foreign keys.

Safe, Deeply-nested Logic

I often found myself working on code similar to this contrived simplification …

@nate-gehringer
nate-gehringer / estimateDynamoDBThroughputSettings.js
Last active September 13, 2021 21:30
Estimates DynamoDB RCU / WCU settings for the specified operation parameters
const estimateDynamoDBThroughputSettings = ({
atomicRead = false,
averageItemSizeBytes,
desiredExecutionDurationHours,
itemCount
}) => {
const totalItemSizeMegabytes = (itemCount * averageItemSizeBytes) / 1024 /* kilobytes */ / 1024 /* megabytes */;
const readUnitsPerItem = atomicRead
? Math.max(Math.ceil(averageItemSizeBytes / 4096) /* 1 RCU = up to 4 KB */, 1) / 2 /* eventually consistent reads use 0.5 RCU */
: (averageItemSizeBytes / 4096 /* 1 RCU = up to 4 KB */) / 2 /* eventually consistent reads use 0.5 RCU */