<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Fredson Gisa Kaze</title>
    <description>The latest articles on DEV Community by Fredson Gisa Kaze (@gisakaze).</description>
    <link>https://dev.to/gisakaze</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F561920%2Fcf43ad0b-1e0d-4777-9e88-9cc5c951387c.jpg</url>
      <title>DEV Community: Fredson Gisa Kaze</title>
      <link>https://dev.to/gisakaze</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gisakaze"/>
    <language>en</language>
    <item>
      <title>Reconsider Using UUID in Your Database</title>
      <dc:creator>Fredson Gisa Kaze</dc:creator>
      <pubDate>Wed, 03 Jul 2024 08:12:16 +0000</pubDate>
      <link>https://dev.to/gisakaze/reconsider-using-uuid-in-your-database-3c4k</link>
      <guid>https://dev.to/gisakaze/reconsider-using-uuid-in-your-database-3c4k</guid>
      <description>&lt;p&gt;Using UUIDs (Universally Unique Identifiers) as primary keys in databases is a common practice for us as developer, but this approach can have significant performance drawbacks. I am going to explore with you two major performance issues associated with using UUIDs as keys in your database tables.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are UUIDs?
&lt;/h3&gt;

&lt;p&gt;A UUID (Universal Unique Identifier) is a 128-bit value used to uniquely identify an object or entity on the internet. Among various versions, UUIDv4 is the most popular. &lt;/p&gt;

&lt;p&gt;Here’s an example of a UUIDv4:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;123e4567-e89b-12d3-a456-426614174000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;UUIDs are like the star players in a football team – they stand out and are unique, but not always the best choice for every play.&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem 1: Insert Performance – The Fumble
&lt;/h3&gt;

&lt;p&gt;When a new record is inserted into a table, the primary key index must be updated to maintain optimal query performance. Indexes are constructed using the B+ Tree data structure, which requires rebalancing with each insertion to stay efficient.&lt;/p&gt;

&lt;p&gt;With UUIDs, the inherent randomness complicates this process, leading to significant inefficiencies. As your database scales, millions of nodes need rebalancing, drastically reducing insert performance when using UUID keys.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE players (
    id UUID PRIMARY KEY,
    name VARCHAR(255)
);

INSERT INTO players (id, name) VALUES ('123e4567-e89b-12d3-a456-426614174000', 'Kevin Lebron');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Tip&lt;/em&gt;: Consider using UUIDv7 instead, as it has inherent ordering that simplifies indexing, like having a well-coordinated offensive line 😊!&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem 2: Higher Storage Requirements
&lt;/h3&gt;

&lt;p&gt;UUIDs consume much more storage compared to auto-incrementing integer keys. Auto-incrementing integers use 32 bits per value, whereas UUIDs use 128 bits – four times more per row. When stored in human-readable form, a UUID can consume up to 688 bits, approximately 20 times more per row.&lt;/p&gt;

&lt;p&gt;This is like getting a penalty flag for excessive celebration. It’s unnecessary and costly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE players (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255)
);

INSERT INTO players (name) VALUES ('Kevin Lebron');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s simulate the impact with two tables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Table 1: Contains 1 million rows with UUIDs.&lt;/li&gt;
&lt;li&gt;Table 2: Contains 1 million rows with auto-incrementing integers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Results&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Total table size&lt;/strong&gt;: The UUID table is about 2.3 times larger than the integer table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ID field size&lt;/strong&gt;: An individual UUID field requires 9.3 times more storage space than an integer field.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ID column size&lt;/strong&gt;: Excluding other attributes, the UUID column is 3.5 times larger than the integer column.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using UUIDs is like getting hit with repeated penalty flags – your storage requirements balloon unnecessarily, impacting performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;While UUIDs are excellent for ensuring uniqueness, they present significant scalability challenges. The performance issues discussed are more noticeable at scale, so for smaller applications, the impact might be minimal. However, it is crucial to understand these implications and design your database accordingly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remember&lt;/strong&gt;: In both football and databases, it's all about making the right plays at the right time!&lt;/p&gt;

&lt;p&gt;If you found this article helpful, please share, and connect with me!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;References&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.cockroachlabs.com/blog/what-is-a-uuid/" rel="noopener noreferrer"&gt;What is a UUID, and what is it used for?&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=a-K2C3sf1_Q" rel="noopener noreferrer"&gt;The Problem with UUID&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=aZjYr87r1b8" rel="noopener noreferrer"&gt;B Trees and B+ Trees. How they are useful in Databases&lt;/a&gt;&lt;/p&gt;

</description>
      <category>performance</category>
      <category>development</category>
      <category>database</category>
    </item>
    <item>
      <title>How to get started with PostgreSQL</title>
      <dc:creator>Fredson Gisa Kaze</dc:creator>
      <pubDate>Tue, 26 Apr 2022 12:31:33 +0000</pubDate>
      <link>https://dev.to/gisakaze/how-to-get-started-with-postgresql-1bpb</link>
      <guid>https://dev.to/gisakaze/how-to-get-started-with-postgresql-1bpb</guid>
      <description>&lt;p&gt;PostgreSQL is an open source Relational Database Management System (RDBMS). In this article, I’ll provide an introduction to getting started with PostgreSQL. The mother site for PostgreSQL is &lt;a href="http://www.postgresql.org" rel="noopener noreferrer"&gt;http://www.postgresql.org&lt;/a&gt; you can read more.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F85udtwnnnqejot3pholq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F85udtwnnnqejot3pholq.gif" alt=" " width="1000" height="420"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Installing PostgreSQL
&lt;/h2&gt;

&lt;p&gt;You can run the command below on your terminal to quickly install PostgreSQL in Ubuntu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ubuntu&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Refresh the apt-get repository
$ sudo apt-get update
// Install PostgreSQL
$ sudo apt-get install postgresql postgresql-contrib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To verify you’ve got PostgreSQL installed, run the following command to check your PostgreSQL version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;postgres --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Others can download the latest version of PostgreSQL &lt;a href="https://www.postgresql.org/download/" rel="noopener noreferrer"&gt;here&lt;/a&gt; and follow the installation steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Login to the PostgreSQL Server&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ sudo -u postgres psql
   -- Run command "psql" as UNIX USER "postgres".
   -- Enter the CURRENT SUPERUSER password for sudo.
psql (14.2 (Ubuntu 14.2-1.pgdg21.10+1))
Type "help" for help

postgres=# help
You are using psql, the command-line interface to PostgreSQL.
Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

-- Display version
postgres=# SELECT version();
                                                           version                                                           
-----------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 14.2 (Ubuntu 14.2-1.pgdg21.10+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0, 64-bit

press q to quit display

-- Quit
postgres=# \q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Create Database, Create Table, CURD (Create-Update-Read-Delete) Records&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-- Login to server
$ sudo -u postgres psql
......

-- List all databases via \l (or \list), or \l+ for more details
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 testdb    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +
           |          |          |             |             | postgres=CTc/postgres+
           |          |          |             |             | python=CTc/postgres
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres

-- Create a new database called testdb
postgres=# CREATE DATABASE testdb;
CREATE DATABASE

-- Connect to testdb database via \c (or \connect)
-- Take note of the change of database name in the command prompt.
postgres=# \c testdb 
You are now connected to database "testdb" as user "postgres".

-- Display all tables (aka relations) via \dt or \dt+ for more details
testdb=# \dt
Did not find any relations.


testdb=# CREATE TABLE IF NOT EXISTS accounts (
    user_id serial PRIMARY KEY, -- AUTO_INCREMENT integer, as primary key
    username VARCHAR ( 50 ) UNIQUE NOT NULL,
    password VARCHAR ( 50 ) NOT NULL,
    email VARCHAR ( 255 ) UNIQUE NOT NULL,
    created_on TIMESTAMP NOT NULL,
        last_login TIMESTAMP 
);

-- Display all tables in the current database, via \dt or \dt+ for more details
testdb=# \dt+
                                     List of relations
 Schema |   Name   | Type  |  Owner   | Persistence | Access method |  Size   | Description 
--------+----------+-------+----------+-------------+---------------+---------+-------------
 public | accounts | table | postgres | permanent   | heap          | 0 bytes | 


-- Quit
testdb=# \q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You need to end your SQL command with a semi-colon (;) every-time or \g. If you forget to enter a semi-colon (;), the command-prompt changes to "dbname-#" to indicate continuation. You can enter the semi-colon on the new line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;More on commands&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;\?: show all psql commands.&lt;/li&gt;
&lt;li&gt;\h sql-command: show syntax on SQL command.&lt;/li&gt;
&lt;li&gt;\c dbname [username]: Connect to database, with an optional username (or \connect).&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Display Commands: You can append + to show more details.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       - \l: List all database (or \list).
       - \d: Display all tables, indexes, views, and sequences.
       - \dt: Display all tables.
       - \dv: Display all views.
       - \di: Display all indexes.
       - \ds: Display all sequences.
       - \dS: Display all system tables.
       - \dT: Display all types.
       - \du: Display all users.
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;See more &lt;a href="https://www.postgresql.org/docs/current/app-psql.html" rel="noopener noreferrer"&gt;commands&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Commonly-used SQL Data Types&lt;/strong&gt;&lt;br&gt;
The commonly-used SQL data types in PostgreSQL are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;INT, SMALLINT:&lt;/code&gt; whole number.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DATE, TIME, TIMESTAMP:&lt;/code&gt; date and time.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NULL:&lt;/code&gt; Represent known value of 0 and empty string).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SERIAL:&lt;/code&gt; auto-increment integer (AUTO_INCREMENT in MySQL).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DOUBLE:&lt;/code&gt; single and double precision floating-point number.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;NUMERIC(m,n):&lt;/code&gt; decimal number with m total digits and n decimal places (DECIMAL(m,n) in MySQL).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CHAR(n) and VARCHAR(n):&lt;/code&gt; fixed-length string of n characters and variable-length string of up to n characters. String are enclosed by single quotes, e.g., 'Fredson', 'Python, django'.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;User-defined types:&lt;/code&gt; The ones that don't come defautly.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>postgres</category>
    </item>
    <item>
      <title>What is a stack and where can it be used?</title>
      <dc:creator>Fredson Gisa Kaze</dc:creator>
      <pubDate>Tue, 18 May 2021 08:57:27 +0000</pubDate>
      <link>https://dev.to/gisakaze/what-is-a-stack-and-where-can-it-be-used-2anc</link>
      <guid>https://dev.to/gisakaze/what-is-a-stack-and-where-can-it-be-used-2anc</guid>
      <description>&lt;p&gt;Stack is a linear data structure that follows a particular order in which the various operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). There are many real-life examples of a stack.&lt;br&gt;
Consider a box containing books, the book which was inserted in lastly will be easily first removed&lt;/p&gt;

</description>
      <category>stackdatastructures</category>
    </item>
    <item>
      <title>10 Tips to quickly improve your UI designs</title>
      <dc:creator>Fredson Gisa Kaze</dc:creator>
      <pubDate>Fri, 19 Feb 2021 10:58:53 +0000</pubDate>
      <link>https://dev.to/gisakaze/10-tips-to-quickly-improve-your-ui-designs-27al</link>
      <guid>https://dev.to/gisakaze/10-tips-to-quickly-improve-your-ui-designs-27al</guid>
      <description>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;You should know your users&lt;br&gt;
Above all else, you have to know who your users are—inside and out. Don't stop at knowing what your users want. Dig deeper and find out what they need.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Define how people use your interface&lt;br&gt;
Before you design your interface, you need to define how people will use it. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set expectations&lt;br&gt;
Make sure users have an idea of what will happen before they do it, for example, what will happen after clicking a certain button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Predict mistakes&lt;br&gt;
People make mistakes, but they shouldn’t always have to suffer the consequences. There are two ways to help lessen the impact of human error:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    -Prevent mistakes before they happen
    -Provide ways to fix them after they happen
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Give feedback—fast&lt;br&gt;
Just make sure your things work quick or in others, word respond quickly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Think carefully about element placement and size&lt;br&gt;
This is a crucial thing in design, you must choose what shows users clearly like if it's the menu button, it should well aligned and seenable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don’t ignore standards&lt;br&gt;
Being highly creative types, designers tend to love to reinvent things—but it’s not always the best idea. You must follow the standards of design.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make your interfaces easy to learn&lt;br&gt;
Simplicity in design is the best practice, so you have to make your design easy to understand.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make decision-making simple&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Listen to the data&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>ux</category>
      <category>design</category>
    </item>
    <item>
      <title>Difference between Linked List and Array in CPP</title>
      <dc:creator>Fredson Gisa Kaze</dc:creator>
      <pubDate>Tue, 16 Feb 2021 19:59:02 +0000</pubDate>
      <link>https://dev.to/gisakaze/difference-between-linked-list-and-array-462e</link>
      <guid>https://dev.to/gisakaze/difference-between-linked-list-and-array-462e</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcepplhkh2sx7rps19dar.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcepplhkh2sx7rps19dar.png" alt="difference-between-arrays-and-linked-list" width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically, an array is a set of similar data objects stored in sequential memory locations under a common heading or a variable name.&lt;/p&gt;

&lt;p&gt;While a linked list is a data structure that contains a sequence of the elements where each element is linked to its next element. There are two fields in an element of the linked list. One is the Data field, and the other is the link field, Data field contains the actual value to be stored and processed. Furthermore, the link field holds the address of the next data item in the linked list. The address used to access a particular node is known as a pointer.&lt;/p&gt;

&lt;p&gt;Another significant difference between an array and a linked list is that Array has a fixed size and required to be declared prior, but Linked List is not restricted to size and expand and contract during execution. Below is a summarized table showing differences clearly&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fql7mwjt0ajm3pjl3mjcx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fql7mwjt0ajm3pjl3mjcx.png" alt="1_Lnb0IARMGORn_c-gYf-24g" width="800" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>java</category>
      <category>python</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
