Flexible Schemas with PostgreSQL and Elasticsearch

2018 Dec26

R
elational Databases typically make use of a rigid schema - predefined tables containing typed columns allowing for a rich set of functionality that would otherwise be impossible. It is both a major strength as well as a major weakness. On one hand strong typing allows databases to expose a rich set of operators, functions and functionality for each of the types. For postgres, this usually presents itself in the form of column types sql syntax to interact with them. On the other hand it means that all of the data in the table is uniform and deviations or alterations are rather difficult to do.

At the day job, I am in the process of migrating a number of applications

Read More
filed under:  postgres elasticsearch json

Exact Match OR Null Queries With Elasticsearch

2017 Dec19

E
lasticsearch is an extremely powerful searchable document store. The more you use it, the more you learn about the more realize how deep the rabbit hole of possibility goes. Except for when it comes `null` values. The Achilles heel of elasticsearch. What it really boils down to is elasticsearch doesn't index `null` values or fields that are missing from a document. Even if you have set up an index mapping and told elasticsearch about your field.

As you might think it can get a little tricky searching document for a field value or where that field is null / missing - especially when combined with other field queries. For example lets say I have some documents that looks something like

Read More
filed under:  elasticsearch

SQL Like Search Queries With Elasticsearch

2017 Nov11
E

lasticsearch is an amazing piece of technology. Built on top of luecine it offers all of he incredible search facilities that you'd expect from a full featured search. What makes elasticsearch so powerful, however, is the fact that it stores the actual data that was originally index as JSON documents. Basically, it is a Full Text Search Database more so than a search engine. This allows elastic search to do things that other search engines can't do like aggregations, scripted queries, multi-query searches, etc; All in addition to the expected searching capabilities like suggestions, spelling corrections, faceting, and so on. For these reasons people are using elasticsearch as the primary data store for massive amounts of data.

One thing

Read More
filed under:  elasticsearch sql

Live Coding On Twitch

2017 Sep14
G

oing to start doing some live coding on twitch! I've been in the open source space for a long while and it seems fitting that this is the next step. I don't really have a schedule in mind or much else lined out. Other than - It's probably happening

Check out my channel on twitch. I'll do my best to send out a heads up when I plan on doing something. I'll probably work on Skyring, Tastypie or maybe dust off some stuff from my megadoomer collection of things.

I'm Twitchin'!

Read More
filed under:  twitch streaming live coding

Exactly Once Execution In A Distributed System

2017 Sep04
S

kyring is a [distributed system for managing timers](https://github.com/esatterwhite/skyring), or delayed execution similar to `setTimeout` in javascript. The difference being that it is handled in a reliable and fault tolerant way. `setTimeout` in javascript is transient. If the running application is restarted or crashes, any pending timers are lost forever. The one guarantee that skyring provides is that a timer will execute after the specified delay, and that it only executes once. Exactly once is an interesting challenge in distributed systems, and Skyring makes use of a number of mechanisms at the node level to achieve this. From a high level, this is what the behavior on individual nodes looks like.

Skyring Node Behavior

Shared Nothing

Skyring follows

Read More

Custom Transports For Skyring

2017 May29
S

kyring is a distributed system for managing timers. When a timer lapses, a message is delivered to destination that you have defined. *How* that message is delivered is configurable. Out of the box, Skyring comes with an `HTTP` transport, and there is an official package enabling [tcp delivery](https://www.npmjs.com/package/@skyring/tcp-transport) of messages with connection pooling. They are pretty easy to write, and you can use any of the tools you are currently used to using.

STDOUT Transport

To illustrate the process, we're going to make a simple transport handler to write the data to stdout. Basically, speaking a transport is just a node.js module that exports a named function

Module [ˈmäjo͞ol] -n.

Read More
filed under:  zmq skyring timers node.js

Getting Started With Skyring Distributed Timers

2017 May01
T

he very idea of distributed timers is complex. Conceptually is full of race conditions and edge cases. [Skyring](https://github.com/esatterwhite/skyring) for Node.js boils the problems space down to a simple to use library and API for building scalable service that need to perform time sensitive, actions. That is a mouthful - Think An email gateway, a web-hook service, auto-dialers for telephony systems. Or in the most practical sense, anytime you might need functionality like [setTImeout](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout) but needs to survive restarts / crashes; Or are using a language that doesn't support non-blocking timers. Skyring fills that gap, and it is easy to use. We can get something

Read More
filed under:  skyring timers node

Build JSON API Responses With Postgres CTEs

2017 Apr30
P

agination is a recurring problem that developers have to deal with when implementing data access layers for APIs. It can be particularly tricky with the more traditional RDMS like [MySQL](https://www.mysql.com/) or [Postgresql](https://www.postgresql.org/). For example, let's say we had an API endpoint that allowed consumers to search a data base of moves. We could search by title, director, starring actors, etc. Our data base has millions of movies, and we know we don't want to return all all the potential matches for every search request. We only want to return the top 25 or so records and indicate in the response that there are more results to query for:

{
  meta: {
    total: 12000

Read More
filed under:  sql postgres node.js

Distributed Timers With Node.js and Skyring

2016 Dec28
W

orking with timers a distributed system is a really nasty problem that pops up more often than most people would like. Something as simple an useful as `setTimeout` / `clearTimeout` becomes brittle, unreliable and a bottle neck in today's stateless scaleable server mindset. Basically, I need to be able to set a timer somewhere in a cluster with out knowing or caring about what server. And reversely, I need to be able to cancel that timer **without** having to know where in the cluster that timer lives. But before we can start to understand possible solutions, let's dive into a use case to understand the problem and why existing solutions aren't suitable replacements.

Scenrios

Un-send an email - A simple

Read More

Distributed Timers with Node.js, Dgram and multicast

2016 Sep30
O

ver the years I have had a handful of times where I have had the need for Multicasting. It usually comes about in service or node ( application ) discovery. Or if you are lucky enough, the dreaded *distributed* `setTimeout` / `clearTimeout`. Every time find a need for it, I spend hours in the documentation trying to remember how to use it, remembering the Node.js Docs for [dgram](https://nodejs.org/api/dgram.html) - which are virtually void of any useful explanation or examples. Finally resorting to finding googling around for the 1 or two examples of multi casting out there and hack something together. It shouldn't like that. It is actually really easy to do with Node.js. Let's

Read More
filed under:  udp multicast dgram networking node