Skip to content

Commit 393115e

Browse files
Merge pull request #604 from wjohnsto/master
mobile banking account dashboard tutorial
2 parents 6b97ef5 + 33db82c commit 393115e

File tree

11 files changed

+316
-53
lines changed

11 files changed

+316
-53
lines changed

docs/howtos/solutions/index-solutions.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,24 @@ Learn how to easily build, test and deploy code for common microservice and cach
132132
</div>
133133

134134
</div>
135+
136+
## Mobile Banking
137+
138+
<div class="row">
139+
<div class="col">
140+
<RedisCard
141+
title="Authentication and Session Storage"
142+
description="Mobile Banking Authentication and Session Storage Using Redis"
143+
page="/howtos/solutions/mobile-banking/session-management"
144+
/>
145+
</div>
146+
147+
<div class="col">
148+
<RedisCard
149+
title="Account Dashboard"
150+
description="Mobile Banking Account Dashboard Using Redis"
151+
page="/howtos/solutions/mobile-banking/account-dashboard"
152+
/>
153+
</div>
154+
155+
</div>
57.4 KB
Loading
67 KB
Loading
239 KB
Loading
316 KB
Loading
135 KB
Loading
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
---
2+
id: index-mb-account-dashboard
3+
title: Mobile Banking Account Dashboard Using Redis
4+
sidebar_label: Mobile Banking Account Dashboard Using Redis
5+
slug: /howtos/solutions/mobile-banking/account-dashboard
6+
authors: [prasan, will]
7+
---
8+
9+
import GeneralAdditionalResources from '../common-mb/additional-resources.mdx';
10+
import MobileBankingSourceCode from '../common-mb/source-code-tip.mdx';
11+
import MobileBankingDataSeeding from '../common-mb/data-seeding.mdx';
12+
13+
<MobileBankingSourceCode />
14+
15+
## What is a mobile banking account dashboard?
16+
17+
An account dashboard is a page in a mobile banking app that instantly renders account highlights to users. A customer can click on any of the accounts on the dashboard to see the real-time account details, such as latest transactions, mortgage amount they have left to pay, checking and savings, etc.
18+
19+
An account dashboard makes a customer's finances easily visible in one place. It reduces financial complexity for the customer and fosters customer loyalty.
20+
21+
The following diagram is an example data architecture for an account dashboard:
22+
23+
![dashboard](./images/dashboard.png)
24+
25+
1. Banks store information in a number of separate databases that support individual banking products
26+
2. Key customer account details (balances, recent transactions) across the banks product portfolio are prefetched into Redis Enterprise using Redis Data Integration (RDI)
27+
3. Redis Enterprise powers customer's account dashboards, enabling mobile banking users to view balances and other high-priority information immediately upon login
28+
29+
## Why you should use Redis for account dashboards in mobile banking
30+
31+
- **Resilience**: Redis Enterprise provides resilience with 99.999% uptime and Active-Active Geo Distribution to prevent loss of critical user profile data
32+
33+
- **Scalability**: Redis Enterprise provides < 1ms performance at incredibly high scale to ensure apps perform under peak loads
34+
35+
- **JSON Support**: Provides the ability to create and store account information as JSON documents with the < 1ms speed of Redis
36+
37+
- **Querying and Indexing**: Redis Enterprise can quickly identify and store data from multiple different databases and index data to make it readily searchable
38+
39+
:::note
40+
41+
Redis Stack supports the [<u>**JSON**</u>](/howtos/redisjson/) data type and allows you to index and querying JSON and [<u>**more**</u>](https://redis.io/docs/stack/). So your Redis data is not limited to simple key-value stringified data.
42+
43+
:::
44+
45+
## Building an account dashboard with Redis
46+
47+
<MobileBankingSourceCode />
48+
49+
Download the above source code and run following command to start the demo application
50+
51+
```sh
52+
docker compose up -d
53+
```
54+
55+
After docker up & running, open [http://localhost:8080/](http://localhost:8080/) url in browser to view application
56+
57+
### Data seeding
58+
59+
<MobileBankingDataSeeding />
60+
61+
### Balance over time
62+
63+
**Dashboard widget**
64+
65+
![Chart](./images/01-ui-balance-over-time.png)
66+
67+
**API endpoint**
68+
69+
| | |
70+
| ------------- | --------------------------------- |
71+
| Endpoint | `/transaction/balance` |
72+
| Code Location | `/routers/transaction-router.js` |
73+
| Parameters | none |
74+
| Return value | `[{x: timestamp, y: value}, ...]` |
75+
76+
The balance endpoint leverages [**Time Series**](https://redis.io/docs/stack/timeseries/), It returns the range of all values from the time series object `balance_ts`. The resulting range is converted to an array of objects with each object containing an `x` property containing the timestamp and a `y` property containing the associated value. This endpoint supplies the time series chart with coordinates to plot a visualization of the balance over time.
77+
78+
```js title="app/routers/transaction-router.js"
79+
const BALANCE_TS = 'balance_ts';
80+
81+
/* fetch transactions up to sometime ago */
82+
transactionRouter.get('/balance', async (req, res) => {
83+
//time series range
84+
const balance = await redis.ts.range(
85+
BALANCE_TS,
86+
Date.now() - 1000 * 60 * 5, //from
87+
Date.now(), //to
88+
);
89+
90+
let balancePayload = balance.map((entry) => {
91+
return {
92+
x: entry.timestamp,
93+
y: entry.value,
94+
};
95+
});
96+
97+
res.send(balancePayload);
98+
});
99+
```
100+
101+
### Biggest spenders
102+
103+
**Dashboard widget**
104+
105+
![Chart](./images/02-ui-biggest-spenders.png)
106+
107+
**API end point**
108+
109+
| | |
110+
| ------------- | -------------------------------- |
111+
| Endpoint | `/transaction//biggestspenders` |
112+
| Code Location | `/routers/transaction-router.js` |
113+
| Parameters | none |
114+
| Return value | `{labels:[...], series:[...] }` |
115+
116+
The biggest spenders endpoint leverages [**sorted sets**](https://redis.io/docs/manual/patterns/indexes/) as a secondary index, It retrieves all members of the sorted set `bigspenders` that have scores greater than zero. The top five or fewer are returned to provide the UI pie chart with data. The labels array contains the names of the biggest spenders and the series array contains the numeric values associated with each member name.
117+
118+
```js title="app/routers/transaction-router.js"
119+
const SORTED_SET_KEY = 'bigspenders';
120+
121+
/* fetch top 5 biggest spenders */
122+
transactionRouter.get('/biggestspenders', async (req, res) => {
123+
const range = await redis.zRangeByScoreWithScores(
124+
SORTED_SET_KEY,
125+
0,
126+
Infinity,
127+
);
128+
let series = [];
129+
let labels = [];
130+
131+
range.slice(0, 5).forEach((spender) => {
132+
series.push(parseFloat(spender.score.toFixed(2)));
133+
labels.push(spender.value);
134+
});
135+
136+
res.send({ series, labels });
137+
});
138+
```
139+
140+
### Search existing transactions
141+
142+
**Dashboard widget**
143+
144+
![Search transactions](./images/03-ui-search-transactions.png)
145+
146+
**API end point**
147+
148+
| | |
149+
| ---------------- | -------------------------------- |
150+
| Endpoint | `/transaction/search` |
151+
| Code Location | `/routers/transaction-router.js` |
152+
| Query Parameters | term |
153+
| Return value | array of results matching term |
154+
155+
The search endpoint leverages [**Search and Query**](https://redis.io/docs/stack/search/), It receives a `term` query parameter from the UI. A [Redis om Node](https://github.com/redis/redis-om-node) query for the fields `description`, `fromAccountName`, and `accountType` will trigger and return results.
156+
157+
```js title="app/routers/transaction-router.js"
158+
transactionRouter.get('/search', async (req, res) => {
159+
const term = req.query.term;
160+
161+
let results;
162+
163+
if (term.length >= 3) {
164+
results = await bankRepo
165+
.search()
166+
.where('description')
167+
.matches(term)
168+
.or('fromAccountName')
169+
.matches(term)
170+
.or('transactionType')
171+
.equals(term)
172+
.return.all({ pageSize: 1000 });
173+
}
174+
res.send(results);
175+
});
176+
```
177+
178+
### Get recent transactions
179+
180+
**Dashboard widget**
181+
182+
![View recent transactions](./images/04-ui-recent-transactions.png)
183+
184+
**API end point**
185+
186+
| | |
187+
| ------------- | -------------------------------- |
188+
| Endpoint | `/transaction/transactions` |
189+
| Code Location | `/routers/transaction-router.js` |
190+
| Parameters | none |
191+
| Return value | array of results |
192+
193+
Even the transactions endpoint leverages [**Search and Query**](https://redis.io/docs/stack/search/). A [Redis om Node](https://github.com/redis/redis-om-node) query will trigger and return ten most recent transactions.
194+
195+
```js title="app/routers/transaction-router.js"
196+
/* return ten most recent transactions */
197+
transactionRouter.get('/transactions', async (req, res) => {
198+
const transactions = await bankRepo
199+
.search()
200+
.sortBy('transactionDate', 'DESC')
201+
.return.all({ pageSize: 10 });
202+
203+
res.send(transactions.slice(0, 10));
204+
});
205+
```
206+
207+
## Ready to use Redis in account dashboard?
208+
209+
Hopefully, this tutorial has helped you visualize how to use Redis for account dashboard, specifically in the context of mobile banking. For additional resources related to this topic, check out the links below:
210+
211+
### Additional resources
212+
213+
- [Mobile Banking Session Management](/howtos/solutions/mobile-banking/session-management)
214+
215+
<GeneralAdditionalResources />
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
This application leverages **Redis core data structures, JSON, TimeSeries, Search and Query features**. The data seeded is later used to show a searchable transaction overview with realtime updates as well as a personal finance management overview with realtime balance and biggest spenders updates.
2+
3+
On application startup in `app/server.js`, a cron is scheduled to create random bank transactions at regular intervals and seed those transactions in to Redis.
4+
5+
```js title="app/server.js"
6+
//cron job to trigger createBankTransaction() at regular intervals
7+
8+
cron.schedule('*/10 * * * * *', async () => {
9+
const userName = process.env.REDIS_USERNAME;
10+
11+
createBankTransaction(userName);
12+
13+
//...
14+
});
15+
```
16+
17+
- The transaction generator creates a randomized banking debit or credit which will reflect on a (default) starting user balance of $100,000.00
18+
- The **transaction data** is saved as a JSON document within Redis.
19+
- To capture **balance over time**, the `balanceAfter` value is recorded in a TimeSeries with the key `balance_ts` for every transaction.
20+
- To track **biggest spenders**, an associated **`fromAccountName`** member within the sorted set `bigspenders` is incremented by the transaction amount. Note that this amount can be positive or negative.
21+
22+
```js title="app/transactions/transactionsGenerator.js"
23+
let balance = 100000.0;
24+
const BALANCE_TS = 'balance_ts';
25+
const SORTED_SET_KEY = 'bigspenders';
26+
27+
export const createBankTransaction = async () => {
28+
//to create random bank transaction
29+
let vendorsList = source.source; //app/transactions/transaction_sources.js
30+
const random = Math.floor(Math.random() * 9999999999);
31+
32+
const vendor = vendorsList[random % vendorsList.length]; //random vendor from the list
33+
34+
const amount = createTransactionAmount(vendor.fromAccountName, random);
35+
const transaction = {
36+
id: random * random,
37+
fromAccount: Math.floor((random / 2) * 3).toString(),
38+
fromAccountName: vendor.fromAccountName,
39+
toAccount: '1580783161',
40+
toAccountName: 'bob',
41+
amount: amount,
42+
description: vendor.description,
43+
transactionDate: new Date(),
44+
transactionType: vendor.type,
45+
balanceAfter: balance,
46+
};
47+
48+
//redis json feature
49+
const bankTransaction = await bankTransactionRepository.save(transaction);
50+
console.log('Created bankTransaction!');
51+
// ...
52+
};
53+
54+
const createTransactionAmount = (vendor, random) => {
55+
let amount = createAmount(); //random amount
56+
balance += amount;
57+
balance = parseFloat(balance.toFixed(2));
58+
59+
//redis time series feature
60+
redis.ts.add(BALANCE_TS, '*', balance, { DUPLICATE_POLICY: 'first' });
61+
//redis sorted set as secondary index
62+
redis.zIncrBy(SORTED_SET_KEY, amount * -1, vendor);
63+
64+
return amount;
65+
};
66+
```
67+
68+
Sample `bankTransaction` data view using [RedisInsight](https://redis.com/redis-enterprise/redis-insight/)
69+
70+
![bank transaction data](./images/bank-transaction-data.png)
71+
72+
![bank transaction json](./images/bank-transaction-json.png)
73+
74+
:::tip
75+
Download [<u>**RedisInsight**</u>](https://redis.com/redis-enterprise/redis-insight/) to view your Redis data or to play with raw Redis commands in the workbench. Learn more by reading the [<u>**RedisInsight tutorial**</u>](/explore/redisinsight/)
76+
:::
172 KB
Loading
144 KB
Loading

0 commit comments

Comments
 (0)