Blue-green deployments with Materialize

Introduction

Prerequisites

What is a Blue-Green Deployment?

Plan Your Deployment

Creating Materialize Deployments

Connecting to Materialize

Adding Materialize Sources

CREATE SOURCE market_orders_raw
FROM PUBNUB
SUBSCRIBE KEY 'sub-c-4377ab04-f100-11e3-bffd-02ee2ddab7fe'
CHANNEL 'pubnub-market-orders';
CREATE VIEW market_orders AS
SELECT
((text::jsonb)->>'bid_price')::float AS bid_price,
(text::jsonb)->>'order_quantity' AS order_quantity,
(text::jsonb)->>'symbol' AS symbol,
(text::jsonb)->>'trade_type' AS trade_type,
to_timestamp(((text::jsonb)->'timestamp')::bigint) AS ts,
''
FROM market_orders_raw;
CREATE MATERIALIZED VIEW avg_bid AS
SELECT symbol,
AVG(bid_price) AS avg
FROM market_orders
GROUP BY symbol;
SELECT * FROM avg_bid;
symbol | avg
------------+--------------------
Apple | 199.3392717416626
Google | 299.40371152970334
Elerium | 155.04668809209852
Bespin Gas | 202.0260593073953
Linen Cloth | 254.34273792647863

Create the route (via DNS or LB) to the blue instance

materialize.example.com. CNAME  12345mz.materialize.cloud.

Performing a Blue-Green Deployment

CREATE SOURCE market_orders_raw
FROM PUBNUB
SUBSCRIBE KEY 'sub-c-4377ab04-f100-11e3-bffd-02ee2ddab7fe'
CHANNEL 'pubnub-market-orders';
CREATE VIEW market_orders AS
SELECT
((text::jsonb)->>'bid_price')::float AS bid_price,
(text::jsonb)->>'order_quantity' AS order_quantity,
(text::jsonb)->>'symbol' AS symbol,
(text::jsonb)->>'trade_type' AS trade_type,
to_timestamp(((text::jsonb)->'timestamp')::bigint) AS ts
FROM market_orders_raw;
CREATE MATERIALIZED VIEW avg_bid AS
SELECT symbol,
trade_type,
AVG(bid_price) AS avg
FROM market_orders
GROUP BY symbol, trade_type;

Update the route to point to green

materialize.example.com. CNAME  54321mz.materialize.cloud.  # Change this to the new hostname

Verifying the Deployment

SELECT * FROM avg_bid;

Alternative approaches to the DNS change

Downside of Blue-Green Deployments

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bobby Iliev

I am a professional System Administrator with a demonstrated history of working in the internet industry. I am a Linux lover