|
| 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 account dashboard for mobile banking? |
| 16 | + |
| 17 | +An account dashboard is a page in a mobile banking app to instantly render 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 | +Account dashboard make customer's finances easily visible in one place. It reduces financial complexity for the customer and fosters customer loyalty |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +1. Banks store information in a number of separate databases that support individual banking products |
| 24 | + |
| 25 | +2. Key customer account details (balances, recent transactions) across the banks product portfolio re prefetched into Redis Enterprise using Redis Data Integration |
| 26 | + |
| 27 | +3. Redis Enterprise powers customers' 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 mobile banking account dashboard? |
| 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 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 |
| 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 | + |
| 66 | + |
| 67 | +**API end point** |
| 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 **[Redis time series](https://redis.io/docs/stack/timeseries/) feature**, 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 all transactions up to an hour 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, |
| 87 | + Date.now(), |
| 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 | + |
| 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 **[Redis 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 less 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 | + |
| 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 Redis **[Search and Query](https://redis.io/docs/stack/search/)** feature, 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 all 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 most recent transactions |
| 179 | + |
| 180 | +**Dashboard widget** |
| 181 | + |
| 182 | + |
| 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 Redis **[Search and Query](https://redis.io/docs/stack/search/)** feature. 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 /> |
0 commit comments