Database Performance Optimization using Lazy Loading with Redis on Online Marketplace Website
Jurnal Elektronik Ilmu Komputer Udayana
Volume 12, No 3. Februari 2024
p-ISSN: 2301-5373
e-ISSN: 2654-5101
Database Performance Optimization using Lazy Loading
with Redis on Online Marketplace Website
Albertus Ivan Suryawana1, Agus Muliantaraa2
a
Inf ormatics Department, Udayana University
Bali, Indonesia
1
2
(Corresponding author)
Abstract
With the pandemic lasting over 2 years, many businesses start to adapting a digital approach of their
business to stay alive. While in the same time, a number of users of digital platform also skyrocketed
due to physical contact restriction policy. This causes a performance hit toward several online services
such as an online marketplace due to high network traffic from many users accessing it in the same
time, including latency issues. In this research, the authors try to implement an application-level caching
with an in-memory database, Redis, using Lazy Loading approach. Beside implementing caching,
authors also compare the performance of using cache and not using cache by load testing both
implementation using similarly built application. Based on the result, there is a performance gain of 3865% based on the load and scenario by using application-level caching.
Keywords: Cache, Cache-Aside Pattern, Lazy Loading, performance optimization, application-level
caching, in-memory database
1.
Introduction
With the pandemic lasting over 2 years since March 2020, many businesses start to migrating their
operation to digital platform, in order to survive due to physical contact restriction policy. Some start to
use social media as an e-commerce platform, while others making their own online services from which
accessible through online. The latter is the case of a certain business called Business X, which name
cannot be disclosed, in which they start building their own online marketplace business to continue
selling several products. Over a year af ter starting an online marketplace, they start noticed a high
latency issue while navigating through the website, due to high network traf fic. The authors try to
analyze the inf rastructure used, and found out there is a bottleneck on the database due to high traffic
mention earlier. To address this issue, the authors try to implement caching into the application, in form
of application-level caching.
Caching is often being used to reduce load coming into the main memory , which commonly known to
be slow, by storing data that frequently accessed in the cache itself. Application-level is a type of caching
in which the implementation of the cache is done by the developer itself based on the condition. Usually,
this type of cache is implemented in the server-side of the application, and mostly relied on in-memory
database such as Redis[1], [2]. In order to avoid additional strain on in-memory database due to
excessive data stored inside, Cache-aside pattern or Lazy-Loading, will be used to limit when data
should be stored. Cache-aside pattern is a type of data synchronization where data is being stored in
the cache on demand[3].Consequently, instead of storing all data directly on the cache, only previously
requested data will be stored inside until its expired or an updat e f or the that data occurred in main
database.
There are several research that has been done regarding caching such as on research done by Saldhi
et al. [1] which analyze perf ormance difference between two Cache System namely, Inf iniSpan and
Hazelcast. In that research, the author suggests to do a comparative performance analysis across
dif ferent cache pattern. Another research with similar interest that has been done is [2] in which a
perf ormance between MySQL database were compared with Redis as cache database. Based on the
result, there are some degree of performance gains by using Write-Through pattern that the writer has
implemented. Although [2]may be similar to this research, there is a dif ference in the type of data
627
Suryawan, Muliantara
Database Performance Optimization using Lazy Loading with Redis on Online Marketplace Website
synchronization pattern being used, where author used Cache-Aside pattern instead of Write-Through
pattern.
2.
Reseach Methods
Due to the nature of the subject, the methodology used on this research mainly consist of 5 stages as
shown on Figure 1, including system requirement analysis, database modeling, cache strategy
modeling, application development, and perf ormance analysis.
Figure 1. Research Methodology
2.1.
System Requirement Analysis
System Requirement Analysis is the f irst stage of System Development Lif e Cycle (SDLC) where the
developer will conduct an analysis to list any requirement needed f or the system. On this research,
there are 3 main f eature that needed to be existed including, user registration and login; get list of
available products and get product’s detail; and checkout an order.
2.2.
Database Modeling
In this research, there are 2 types of databases being used f or the application, a relational database
using MySQL, and an in-memory database namely Redis. Redis is chosen due to its popularity as a
cache management system with high flexibility of usage such as shown in [4]. MySQL will be used as
the main database, where all of the data will be stored, and Redis will be used as a cache layer, where
all cached data will be store based on the cache strategy modeling being used. MySQL database
consist of 4 tables as shown in Figure 2 and Figure 3.
Figure 2. Entity Relational Diagram
628
Jurnal Elektronik Ilmu Komputer Udayana
Volume 12, No 3. Februari 2024
p-ISSN: 2301-5373
e-ISSN: 2654-5101
Figure 3. Relational Database Model
Table userdata contains all user data including email, password, full name, and access privilege level.
Table orders and order_details contain all order data such as product bought, quantity, price at the time
bought, and user who ordered it. Table products contains all product data such as product name, price,
and remaining stock. While MySQL can be model af ter their table, Redis in the other hand is a keyvalue database in which described as shown in Table 1. Standardized naming scheme for Redis’ key
is being implemented to keep the caching logic simple and avoid several problems in the f uture such
as name collisions [5]
Table 1. Redis Naming Scheme
Field
Naming Scheme
Userdata Cache
user:<userdata_id>
Session Cache
session:<session_id>
User-Session Index Key
user-session:<user_id>
Product Detail Cache
product:<product_id>
All Product Summary
product:summary
2.3.
Expiry Duration
1 Hour
5 Minutes
5 Minutes
1 Hour
1 Hour
Cache Strategy Modeling
There are several ways to implement data synchronization between main database and the cache. As
mention in the introduction, the author chooses to implemented a Cache-Aside pattern in which data is
stored in the cache when there is a request f or it, and retain in the cache until its expiry time reached
or the corresponding data is updated in the database. In Figure 4, t (...truncated)