Reducing number of dB calls

Introduction

In my experience building backend applications, one of the key factors in improving performance is reducing the number of I/O operations—such as database calls and external API requests—your app makes. Every I/O operation adds l…


This content originally appeared on DEV Community and was authored by Chidiebere Ogujeiofor

Introduction

In my experience building backend applications, one of the key factors in improving performance is reducing the number of I/O operations—such as database calls and external API requests—your app makes. Every I/O operation adds latency and can bottleneck your application's overall performance.

Of all I/O operations, database queries are the most common, and if not optimized, can severely slow down your app. In this series of articles, I will explore common scenarios where an application might make multiple database calls unnecessarily and demonstrate techniques to optimize those operations.

We will use a PostgreSQL database for the examples, but the techniques discussed can be applied to any SQL-based database.

Sample Data

For our examples, we will use a simplified schema of a ticketing application. The app allows event owners to create and manage events, while users can purchase tickets through an API.

Here are the sample tables we'll work with:

Users Table

Fields Type Constraints
first_name text
last_name text
id VARCHAR(30) PK

events Table

Fields Type Constraints
title text
owner_id text FK -> Users
id VARCHAR(30) PK

tickets Table

Fields Type Constraints
event_id text FK -> events
id VARCHAR(30) PK
title text
amount INT
quantity INT
quantity_sold INT

quantity: represents the number of that tickets that is available at the beginning. This would be like the number of seats in a concert
quantity_sold: is the number of tickets that has been sold.

See you in the next article

Let's explore the first type of problem in the next article.

Alt text of image


This content originally appeared on DEV Community and was authored by Chidiebere Ogujeiofor


Print Share Comment Cite Upload Translate Updates
APA

Chidiebere Ogujeiofor | Sciencx (2024-09-24T18:34:59+00:00) Reducing number of dB calls. Retrieved from https://www.scien.cx/2024/09/24/reducing-number-of-db-calls/

MLA
" » Reducing number of dB calls." Chidiebere Ogujeiofor | Sciencx - Tuesday September 24, 2024, https://www.scien.cx/2024/09/24/reducing-number-of-db-calls/
HARVARD
Chidiebere Ogujeiofor | Sciencx Tuesday September 24, 2024 » Reducing number of dB calls., viewed ,<https://www.scien.cx/2024/09/24/reducing-number-of-db-calls/>
VANCOUVER
Chidiebere Ogujeiofor | Sciencx - » Reducing number of dB calls. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/24/reducing-number-of-db-calls/
CHICAGO
" » Reducing number of dB calls." Chidiebere Ogujeiofor | Sciencx - Accessed . https://www.scien.cx/2024/09/24/reducing-number-of-db-calls/
IEEE
" » Reducing number of dB calls." Chidiebere Ogujeiofor | Sciencx [Online]. Available: https://www.scien.cx/2024/09/24/reducing-number-of-db-calls/. [Accessed: ]
rf:citation
» Reducing number of dB calls | Chidiebere Ogujeiofor | Sciencx | https://www.scien.cx/2024/09/24/reducing-number-of-db-calls/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.