Sunday, February 24, 2019

Posgres as "Document DB" with JSONB

Postgres JSON: Unleash the Power of Storing JSON in Postgres | Codeship | via @codeship

CREATE TABLE cards ( id integer NOT NULL, board_id integer NOT NULL, data jsonb );

INSERT INTO cards VALUES (1, 1, '{"name": "Paint house", "tags": ["Improvements", "Office"], "finished": true}');

SELECT data->>'name' AS name FROM cards

SELECT * FROM cards WHERE data->>'finished' = 'true';

CREATE INDEX idxfinished ON cards ((data->>'finished'));

As of Postgres 9.4, along with the JSONB data type came GIN (Generalized Inverted Index) indexes. With GIN indexes, we can quickly query data using the JSON operators @>, ?, ?&, and ?

CREATE INDEX idxgindata ON cards USING gin (data); 

SELECT count(*) FROM cards WHERE data @> '{"tags": ["Clean", "Kitchen"]}';
How to query JSONB, beginner sheet cheat – Hacker Noon

PostgreSQL: Documentation: 10: 8.14. JSON Types

Fission: Serverless Functions for Kubernetes: FaaS

fission/fission: Fast Serverless Functions for Kubernetes @ GitHub, Apache 2 license

written in GoLang, supporting execution environments for
Go, JVM. .NET, NodeJS, Python, Ruby, PHP, and even Perl :)

trigger is something that maps an event to a function; Fission as of today supports HTTP requesttimed, and message queue triggers.

Performance: 100msec cold start
Fission maintains a pool of "warm" containers that each contain a small dynamic loader. When a function is first called, i.e. "cold-started", a running container is chosen and the function is loaded. This pool is what makes Fission fast: cold-start latencies are typically about 100msec.

Serverless Functions for Kubernetes - Fission

"What is Fission?
Fission is a framework for serverless functions on Kubernetes.

Write short-lived functions in any language, and map them to HTTP requests (or other event triggers).

Deploy functions instantly with one command. There are no containers to build, and no Docker registries to manage."