Querying Microservices with the CQRS and Materialized View Pattern

How to speed up and scale-out inter-service queries using a dedicated materialized view database that caches queries.

Dunith Danushka
Tributary Data

--

Photo by Cleyder Duque from Pexels

The Microservices architecture mandates keeping service’s data private, promoting the use of database per service pattern.

That brings up challenges when one service tries to access the data owned by another service. There are two patterns to implement that; the API composition pattern and the CQRS based materialized view pattern.

This post digs into the details of using materialized views to scale out the inter-service query operations.

Background

Before we dive deep, let me set the stage for our discussion.

Imagine we have the following customer loyalty platform built on top of Kafka.

The TransactionPerformed events coming from POS and E-Commerce channels are written to the Transactions topic in Kafka. Those events may or may not contain the customer’s loyalty membership ID.

--

--

Dunith Danushka
Tributary Data

Editor of Tributary Data. Technologist, Writer, Senior Developer Advocate at Redpanda. Opinions are my own.