← Back to list

Relational vs. Non-Relational Databases: Understanding the Right Fit with a Real Example

Databases are the backbone of modern applications, helping store, retrieve, and manage data efficiently. When building an application, one…

Lakhan Singh · 2025-03-18 18:58 · 0 claps · 2.7 min read
#golang #relational-databases #databaseskills
Open on Medium ↗

Relational vs. Non-Relational Databases: Understanding the Right Fit with a Real Example

Databases are the backbone of modern applications, helping store, retrieve, and manage data efficiently. When building an application, one of the key decisions is choosing between Relational Databases (SQL) and Non-Relational Databases (NoSQL). But what’s the difference, and how does this impact real-world applications like live match scoring updates?

Let’s break it down with PostgreSQL (a relational database) and Redis (a non-relational database) to see how they handle a live match scenario.

@graphersid

@graphersid

What is a Relational Database?

A Relational Database (SQL-based) follows a structured approach where data is stored in tables with defined relationships. These databases use Structured Query Language (SQL) for data operations and ensure ACID (Atomicity, Consistency, Isolation, Durability) compliance, making them ideal for applications requiring data consistency and integrity.

Example: PostgreSQL for Match Score Storage

Imagine a sports website tracking cricket, football, or basketball match scores. A relational database like PostgreSQL would be perfect for storing historical match data, player statistics, and user preferences.

Schema Example in PostgreSQL:

CREATE TABLE matches (
    match_id SERIAL PRIMARY KEY,
    team_a VARCHAR(50),
    team_b VARCHAR(50),
    date TIMESTAMP,
    venue VARCHAR(100)
);
CREATE TABLE match_scores (
    score_id SERIAL PRIMARY KEY,
    match_id INT REFERENCES matches(match_id),
    team VARCHAR(50),
    score INT,
    updated_at TIMESTAMP DEFAULT NOW()
);

Here, the matches table stores details about each match, while match_scores logs every score update. This structure ensures historical records remain intact and data consistency is maintained.

What is a Non-Relational Database?

A Non-Relational Database (NoSQL-based) is more flexible and can store data in formats like key-value pairs, documents, graphs, or wide columns. These databases are optimized for speed and scalability, making them perfect for real-time applications.

Example: Redis for Real-Time Match Updates

For a live sports app where every second counts, a relational database like PostgreSQL alone is not enough. That’s where Redis, a high-speed, in-memory NoSQL database, comes in.

Redis stores data in a key-value format, allowing instant retrieval. When a goal is scored or a wicket falls, Redis can update and serve data in milliseconds, making it ideal for live dashboards and real-time notifications.

Storing Live Scores in Redis:

SET match:101:score "Team A 1 - 0 Team B"
EXPIRE match:101:score 600  # Automatically remove old scores after 10 minutes

In this example, the match score is stored as a key-value pair, and it automatically expires after 10 minutes to keep only the latest relevant data.

How They Work Together in a Live Match Scenario

A real-world sports application often uses a combination of relational and non-relational databases:

PostgreSQL (Relational)

  • Stores match schedules, teams, player stats, and user preferences.
  • Keeps historical match data for analytics and reports.
  • Ensures data consistency and structured queries

Redis (Non-Relational)

  • Handles real-time match score updates.
  • Provides instant score retrieval for live dashboards.
  • Reduces database load by caching frequently accessed data.

Example Workflow:

  • A football match starts between Team A and Team B.
  • As goals are scored, the live score is updated in Redis (match:101:score -> "Team A 2 - 1 Team B").
  • The frontend app fetches live updates from Redis instead of querying PostgreSQL repeatedly.
  • At the end of the match, the final score is persisted into PostgreSQL for long-term storage.

Which One Should You Use?

  • Use PostgreSQL when you need structured, relational data with relationships (e.g., storing player stats, match history).
  • Use Redis when you need real-time performance (e.g., live match updates, caching frequently accessed data).
  • For a complete system, use both togetherRedis for speed and PostgreSQL for persistence.

Conclusion

Choosing the right database depends on your use case. If you’re building a real-time sports update platform, PostgreSQL alone would be too slow, while Redis alone would lose historical data. By combining both, you get the best of both worlds — speed and persistence.

So, next time you check live match scores, remember that it’s not just a simple number update — it’s a carefully designed system working behind the scenes!


메타데이터
post_id
bc41bd9424f3
slug
relational-vs-non-relational-databases-understanding-the-right-fit-with-a-real-example-bc41bd9424f3
url
https://medium.com/@lakhans7/relational-vs-non-relational-databases-understanding-the-right-fit-with-a-real-example-bc41bd9424f3
canonical_url
https://medium.com/@lakhans7/relational-vs-non-relational-databases-understanding-the-right-fit-with-a-real-example-bc41bd9424f3
author_url
https://medium.com/@lakhans7
status
ok
fetched_at
2026-06-20 20:29:01