Skip to content

Commit 4f9fed8

Browse files
committed
mern ebook added
1 parent 68b51fd commit 4f9fed8

File tree

7 files changed

+129
-8
lines changed

7 files changed

+129
-8
lines changed

docs/ebooks/nosql-data-modeling-patterns.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Notice that in **Code Example 3** we are using the `FT.SEARCH` (RediSearch) comm
172172

173173
```python title="Code Example 4"
174174
async def get_product_details(product_id: str):
175-
eturn await Product.get(product_id)
175+
return await Product.get(product_id)
176176
```
177177

178178
When using Redis, you can use RedisInsight as a GUI tool to visualize and interact with the data in your database. **Picture 4** shows you what a `Products` document looks like.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
id: three-caching-design-patterns
3+
title: 3 design patterns to speed up MEAN and MERN stack applications
4+
image: /img/ebooks/three-caching-design-patterns/three-caching-design-patterns.png
5+
sidebar_label: 3 design patterns to speed up MEAN and MERN stack applications
6+
slug: /ebooks/three-caching-design-patterns
7+
editUrl: false
8+
showLastUpdateTime: false
9+
---
10+
11+
import Excerpt from '@theme/Excerpt';
12+
import CachingMovieAppDesign from '../howtos/solutions/caching-architecture/common-caching/caching-movie-app.mdx';
13+
import SourceCodeMovieApp from '../howtos/solutions/caching-architecture/common-caching/source-code-movie-app.mdx';
14+
15+
<Excerpt
16+
cta="https://redis.com/docs/three-design-patterns-to-speed-up-mean-and-mern-stack-applications/"
17+
image={frontMatter.image}
18+
title={frontMatter.title}>
19+
20+
## Introduction
21+
22+
**If you don't design and build software with attention to performance, your applications can encounter significant bottlenecks when they go into production.**
23+
24+
Over time, the development community has learned common techniques that work as reliable **design patterns** to solve well-understood problems, including application performance.
25+
26+
So what are design patterns? They are recommended practices to solve recurring design problems in software systems. A design pattern has four parts: a name, a problem description (a particular set of conditions to which the pattern applies), a solution (the best general strategy for resolving the problem), and a set of consequences.
27+
28+
Two development stacks that have become popular ways to build Node.js applications are the **MEAN** stack and the **MERN** stack. The MEAN stack is made up of the MongoDB database, the Express and Angular.js frameworks, and Node.js. It is a pure JavaScript stack that helps developers create every part of a website or application. In contrast, the MERN stack is made up of MongoDB, the Express and ReactJS frameworks, and Node.js.
29+
30+
Both stacks work well, which accounts for their popularity. But it doesn't mean the software generated runs as fast as it can—or as fast as it needs to.
31+
32+
In this post, we share one popular design pattern that developers use with Redis to improve application performance with MEAN and MERN stack applications: the `master data-lookup pattern`. We explain the pattern in detail and accompany it with an overview, typical use cases, and a code example. Our intent is to help you understand when and how to use this particular pattern in your own software development. The Ebook has other patterns too like `The cache-aside pattern` and `The write-behind pattern`
33+
34+
## Building a movie application
35+
36+
<CachingMovieAppDesign />
37+
38+
This tutorial uses a GitHub sample demo that was built using the following tools:
39+
40+
- **Frontend**: ReactJS (18.2.0)
41+
- **Backend**: Node.js (16.17.0)
42+
- **Database**: MongoDB
43+
- **Cache and database**: Redis stack (using Docker)
44+
45+
<SourceCodeMovieApp />
46+
47+
## The master data-lookup pattern
48+
49+
One ongoing developer challenge is to (swiftly) create, read, update, and (possibly) delete data that lives long, changes infrequently, and is regularly referenced by other data, directly or indirectly. That's a working definition of master data, especially when it also represents the organization's core data that is considered essential for its operations.
50+
51+
Master data generally changes infrequently. Country lists, genres, and movie languages usually stay the same. That presents an opportunity to speed things up. You can address access and manipulation operations so that [data consistency](https://redis.com/blog/database-consistency/) is preserved and data access happens quickly.
52+
53+
From a developer's point of view, master data lookup refers to the process by which master data is accessed in business transactions, in application setup, and any other way that software retrieves the information. Examples of master data lookup include fetching data for user interface (UI) elements (such as drop-down dialogs, select values, multi-language labels), fetching constants, user access control, theme, and other product configuration. And you can do that even when you rely primarily on MongoDB as a persistent data store.
54+
55+
![pattern](/img/ebooks/three-caching-design-patterns/pattern-01.jpg)
56+
57+
To serve master data from Redis, preload the data from MongoDB.
58+
59+
1. Read the master data from MongoDB on application startup and store a copy of the data in Redis. This pre-caches the data for fast retrieval. Use a script or a cron job to repeatedly copy master data to Redis.
60+
1. The application requests master data.
61+
1. Instead of MongoDB serving the data, the master data will be served from Redis.
62+
63+
### Use cases
64+
65+
Consider this pattern when you need to
66+
67+
- **Serve master data at speed**: By definition, nearly every application requires access to master data. Pre-caching master data with Redis delivers it to users at high speed.
68+
- **Support massive master tables**: Master tables often have millions of records. Searching through them can cause performance bottlenecks. Use Redis to perform real-time search on the master data to increase performance with sub-millisecond response.
69+
- **Postpone expensive hardware and software investments**: Defer costly infrastructure enhancements by using Redis. Get the performance and scaling benefits without asking the CFO to write a check.
70+
71+
### Demo
72+
73+
The image below illustrates a standard way to showcase a UI that is suitable for master data lookups. The developer responsible for this application would treat certain fields as master data, including movie language, country, genre, and ratings, because they are required for common application transactions.
74+
75+
Consider the pop-up dialog that appears when a user who wants to add a new movie clicks the movie application plus the icon. The pop-up includes drop-down menus for both country and language. In this demonstration, Redis loads the values.
76+
77+
![demo-03](/img/ebooks/three-caching-design-patterns/demo-03.png)
78+
79+
### Code
80+
81+
The two code blocks below display a fetch query of master data from both MongoDB and Redis that loads the country and language drop-down values.
82+
83+
Previously, if the application used MongoDB, it searched the static database to retrieve the movie's country and language values. That can be time-consuming if it's read from persistent storage—and is inefficient if the information is static.
84+
85+
```js
86+
*** BEFORE (MongoDB)***
87+
*** MongoDB regular search query ***
88+
function getMasterCategories() {
89+
...
90+
db.collection("masterCategories").find({
91+
statusCode: {
92+
$gt: 0,
93+
},
94+
category: {
95+
$in: ["COUNTRY", "LANGUAGE"],
96+
},
97+
});
98+
...
99+
}
100+
```
101+
102+
Instead, the “after” views in the code blocks show that the master data can be accessed with only a few lines of code—and much faster response times.
103+
104+
```js
105+
*** AFTER (Redis) ***
106+
*** Redis OM Node query ***
107+
function getMasterCategories() {
108+
...
109+
masterCategoriesRepository
110+
.search()
111+
.where("statusCode")
112+
.gt(0)
113+
.and("categoryTag")
114+
.containOneOf("COUNTRY", "LANGUAGE");
115+
...
116+
}
117+
```
118+
119+
## Download the E-book
120+
121+
**Sensing a pattern here?**
122+
The master data-lookup pattern is not the only design pattern you can use to improve application performance.
123+
124+
</Excerpt>

docs/howtos/solutions/caching-architecture/cache-prefetching/index-cache-prefetching.mdx

-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ Imagine you're building a movie streaming platform. You need to be able to provi
3232

3333
One ongoing developer challenge is to swiftly create, read, update, and delete master data. You might store your master data in a system of record like a SQL database or document database, and then use Redis as a cache to speed up lookups for that data. Then, when an application requests master data, instead of coming from the system of record, the master data is served from Redis. This is called the "master data-lookup" pattern.
3434

35-
Consider this pattern when you need to:
36-
37-
1. Serve master data at speed and scale
38-
1. Support massive master tables
39-
1. Postpone expensive hardware and software investments
40-
4135
From a developer's point of view, "master data lookup" refers to the process by which master data is accessed in business transactions, in application setup, and any other way that software retrieves the information. Examples of master data lookup include fetching data for user interface (UI) elements (such as drop-down dialogs, select values, multi-language labels), fetching constants, user access control, theme, and other product configuration.
4236

4337
Below you will find a diagram of the data flow for prefetching master data using Redis with MongoDB as the system of record.

sidebars.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,10 @@ module.exports = {
609609
{
610610
type: 'category',
611611
label: 'E-books',
612-
items: ['ebooks/nosql-data-modeling-patterns'],
612+
items: [
613+
'ebooks/nosql-data-modeling-patterns',
614+
'ebooks/three-caching-design-patterns'
615+
],
613616
},
614617
],
615618
};
Loading
Loading
Loading

0 commit comments

Comments
 (0)