In our last blog about our Quality Assurance (QA) team, we gave an overview of the QA process, including our software and testing methods. One of our key tools during testing is the Materialize Emulator, a Docker image that allows you to maintain a locally hosted version of Materialize.
But there's an important caveat: the Materialize Emulator cannot support production workloads. The Materialize Emulator lacks critical features of our cloud platform, such as fault tolerance and horizontal scalability. However, it does include a local web UI (Materialize Console) available at http://localhost:6874. The Emulator is great for testing and prototyping.
In the following blog, we'll outline a step-by-step walkthrough of how to use the Materialize Emulator.
Materialize Emulator: What Is It?
The Materialize Emulator is an all-in-one Docker image available on Docker Hub for testing and evaluation purposes. The Emulator is not representative of Materialize’s performance and full feature set.
To view a comparison between the Materialize Emulator and the Materialize cloud platform, see the table below:
Materialize Emulator
Materialize SaaS
Production deployments
❌ Not suitable due to performance and license limitations.
✔️
Performance
❌ Limited. Services are bundled in a single container.
✔️ High. Services are scaled across many machines.
Sample data
✔️ Quickstart data source
✔️ Quickstart data source
Data sources
✔️ Connect using a streamlined GUI
✔️ Connect using a streamlined GUI
Version upgrades
✔️ Manual, with no data persistence
✔️ Automated, with data persistence
GUI
✔️ Materialize Console (http://localhost:6874)
✔️ Materialize Console
We've always used the Materialize Emulator for testing, except for the kind that requires cloud integration with Kubernetes.
If you want to use Materialize in production scenarios, sign up for a free trial account or schedule a demo.
Step-by-Step Walkthrough: How to Use the Materialize Emulator
Let's walk through a basic example of how to use the Materialize Emulator with a PostgreSQL source. The only requirements are Docker and the postgres-client (psql).
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
bash
We'll publish the ports to localhost, since Materialize is running without authentication. Without a NAT or firewall, anyone on the internet can connect to your Materialize instance. You can specify ports if you want to allow access, such as: -p 6874:6874, -p 6875:6875, or -p 6876:6876.
Note that we set MZ_EAT_MY_DATA=1, which disables commands like fsync, so that we might lose data in case of a system crash. Since we are only using the Materialize emulator for local testing, we don't mind the risk of data loss. If you are interested in running production workloads on Materialize, check out Materialize Cloud, Self-managed Materialize or at least don't set MZ_EAT_MY_DATA=1 in your Materialize emulator.
Now Materialize is running locally.
- Open the Materialize Console (web UI) at
http://localhost:6874to use the built-in SQL Shell. - Alternatively, connect with
psql:
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
text
Let's start up a Postgres server:
1 | |
2 | |
3 | |
4 | |
bash
Connect to the Postgres server. Then generate a simple table. We will replicate this table to Materialize.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
text
Now use Materialize to connect to the Postgres instance:
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
text
That's how you replicate the Postgres table in Materialize. Now let's perform a query. Let's execute a one-off query on both Materialize and Postgres. We'll design a heavy workload.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
text
Materialize performs the query in 37 seconds, while Postgres performs the query in 2 seconds. This is because Materialize is not designed for one-off queries.
Materialize is optimized for materialized views that update incrementally. Read more about how materialized views work in Materialize. Let's create a materialized view as follows:
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
text
With Materialize, every change to the source table (t1) in Postgres will only require a small amount of incremental work to update the mv materialized view. This is done during INSERT, not during SELECT. And you can use declarative SQL to define the whole view.
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
text
You can also subscribe to the the materialized view and receive instant updates about all of the changes:
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
text
This is the output (timestamp, added (1)/removed (-1), value) when these commands run in Postgres:
1 | |
2 | |
3 | |
4 | |
text
To clean up, we can stop the Docker containers again:
1 | |
2 | |
3 | |
bash
And that's it! This is how you launch the Docker image, and define a materialized view, using the Materialize Emulator.
Shell Script: Materialize Emulator as a Docker Compose Project
To tie things together, here is a small shell script (run.sh) that runs the Materialize Emulator as a Docker Compose project.
The shell script contains many of Materialize's features, including a materialized view mv that combines the data of all these sources:
Also, the script uses the following to get the mv out of Materialize:
- Postgres wire protocol using
psql - HTTP API using
curl - Redpanda (Kafka-compatible) sinks
You can copy the full shell script below:
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | |
93 | |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | |
154 | |
155 | |
156 | |
157 | |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | |
183 | |
184 | |
185 | |
186 | |
187 | |
188 | |
189 | |
190 | |
191 | |
192 | |
193 | |
194 | |
195 | |
196 | |
197 | |
198 | |
199 | |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | |
217 | |
218 | |
219 | |
220 | |
221 | |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | |
230 | |
231 | |
232 | |
233 | |
234 | |
235 | |
bash
Now you can start up a Materialize Emulator in under a minute:
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
text
It's that simple — just use the shell script to launch your Materialize Emulator. And if you prefer a GUI, open the local Materialize Console at http://localhost:6874.
Materialize Emulator: Test Quickly During Development
While Materialize is best experienced in our cloud, the Materialize Emulator allows you to quickly test your releases in a non-production environment.
Although the Materialize Emulator lacks many critical features included in the cloud version, the ability to test rapidly is helpful during development.
Try our Materialize Emulator right now to build your apps more efficiently! And sign up for a free trial of Materialize to see what our full cloud product is like.