<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Databases Archives - Codersee blog- Kotlin on the backend</title>
	<atom:link href="https://blog.codersee.com/category/databases/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.codersee.com/category/databases/</link>
	<description>Kotlin &#38; Backend Tutorials - Learn Through Practice.</description>
	<lastBuildDate>Wed, 16 Apr 2025 04:50:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://blog.codersee.com/wp-content/uploads/2025/04/cropped-codersee_logo_circle_2-32x32.png</url>
	<title>Databases Archives - Codersee blog- Kotlin on the backend</title>
	<link>https://blog.codersee.com/category/databases/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>MongoDB Overview. Introduction To The Most Popular NoSQL DB</title>
		<link>https://blog.codersee.com/mongodb-overview-introduction-to-the-most-popular-nosql-db/</link>
					<comments>https://blog.codersee.com/mongodb-overview-introduction-to-the-most-popular-nosql-db/#respond</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Tue, 14 Feb 2023 06:00:48 +0000</pubDate>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MongoDB]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=5504225</guid>

					<description><![CDATA[<p>This MongoDB overview will be a great introduction to the most popular NoSQL database- from its benefits to real-life use cases.</p>
<p>The post <a href="https://blog.codersee.com/mongodb-overview-introduction-to-the-most-popular-nosql-db/">MongoDB Overview. Introduction To The Most Popular NoSQL DB</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hello friend and welcome to the <strong>MongoDB overview </strong>🙂 In this introduction, we will cover everything from its <strong>genesis, benefits, and drawbacks</strong> to<strong> real-life use cases</strong>.</p>
<p>Please keep in mind this is the 4th blog post in a series about <strong>the most popular databases</strong>, and you can find the previous articles right here:</p>
<ul>
<li><a href="https://blog.codersee.com/discover-postgresql-comprehensive-introduction/">Discover the Power of PostgreSQL: A Comprehensive Introduction</a></li>
<li><a href="https://blog.codersee.com/mysql-essentials-fast-paced-introduction/">MySQL Essentials: A Fast-Paced Introduction</a></li>
<li><a href="https://blog.codersee.com/mysql-essentials-fast-paced-introduction/">Redis Database Explained</a></li>
</ul>
<p>Please sit back, relax, and get ready to discover why MongoDB is taking the world by storm.</p>
<h2>Explainer Animation</h2>
<p>If you enjoy <strong>whiteboard animations</strong>, then right here you can find a video version of this article:</p>
<div style="text-align: center; width: 80%; margin-left: 10%;">
<a href="https://blog.codersee.com/mongodb-overview-introduction-to-the-most-popular-nosql-db/"><img decoding="async" src="https://blog.codersee.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2FIPlERcyb25E%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></p>
</div>
<p>&nbsp;</p>
<p>If you find this content useful,<strong> please leave a subscription </strong> 😉</p>
<h2>MongoDB History</h2>
<p>As the first thing in our MongoDB overview, let&#8217;s take a second to learn more about its genesis.</p>
<p>MongoDB&#8217;s history starts in <strong>October 2007</strong> in a company called <strong>10gen</strong>. The founders were looking for a scalable solution, capable of dealing with a high volume in their internal project. (Un)Fortunately, at that time relational databases were not well-suited to handle the kind of semi-structured data they needed. As a result, they decided to build their own NoSQL database with the scalability and large amounts of unstructured data handling in mind.</p>
<p>Almost two years later, in <strong>February 2009</strong>, Mongo was released as an open-source project. Since then, it quickly gained popularity among developers and businesses who were looking for more flexible solutions. Of course, compared to relational databases.</p>
<p><strong>In 2013</strong>, 10gen changed its name to MongoDB, reflecting the growing popularity of the database.</p>
<p>Today, Mongo is widely used by organizations of all sizes, across various industries. Not to mention, we can choose not only between the Community and Enterprise editions but also a cloud-based database as a service called MongoDB Atlas.</p>
<h2>MongoDB Overview</h2>
<p>MongoDB is written in C++ and uses a binary form of JSON called <strong>BSON (Binary JSON)</strong> to store data. These documents can have fields that hold values of different types, such as:</p>
<ul>
<li>strings,</li>
<li>numbers,</li>
<li>arrays,</li>
<li>and even nested documents.</li>
</ul>
<p>Just like rows in relational databases are combined together in tables, Mongo <strong>documents</strong> are grouped in <strong>collections</strong>. Of course, with one, important difference: each document can have a different structure.</p>
<figure id="attachment_5504238" aria-describedby="caption-attachment-5504238" style="width: 751px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" class="wp-image-5504238 size-full" src="http://blog.codersee.com/wp-content/uploads/2023/01/mongodb_collection_and_document_viewed_in_compass.png" alt="Image is a screenshot from MongoDB Compass and is an overview of Mongo documents stored in an collection. " width="751" height="575" srcset="https://blog.codersee.com/wp-content/uploads/2023/01/mongodb_collection_and_document_viewed_in_compass.png 751w, https://blog.codersee.com/wp-content/uploads/2023/01/mongodb_collection_and_document_viewed_in_compass-300x230.png 300w" sizes="(max-width: 751px) 100vw, 751px" /><figcaption id="caption-attachment-5504238" class="wp-caption-text">Example collection</figcaption></figure>
<p>When it comes to <strong>scalability</strong>, MongoDB uses a sharding architecture to scale horizontally. Sharding, in simple words, allows a Mongo cluster to store more data than can fit on a single server by automatically partitioning the data across multiple machines. In such a situation, each shard contains a subset of the data and the query will be directed to the appropriate shard based on the query.</p>
<p>Of course, MongoDB also provides additional advanced features, like complex query language, indexing, a full-text search, and a replica set mechanism.</p>
<h2>Mongo Advantages</h2>
<p>So, with all of that covered, we can take a while to learn a couple of <strong>MongoDB advantages: </strong></p>
<ul>
<li>Firstly, <strong>flexibility</strong>. As I already mentioned in this MongoDB overview, documents within a collection do not need to have the same structure, or fields, unlike traditional relational databases. Mongo allows for a flexible schema and can be a great choice for some projects.</li>
<li>Moreover, <strong>document-oriented storage </strong>makes it relatively easy to work with MongoDB using popular programming languages that have built-in support for JSON.</li>
<li>Thirdly, <strong>great performance</strong>. Mongo is designed for high performance and can handle large amounts of data.</li>
<li>Additionally, <strong>scalability</strong> and <strong>high availability</strong>. MongoDB can be easily scaled and comes with built-in support for automatic failover and replication.</li>
<li>And finally- <strong>it&#8217;s easy to use</strong>. Mongo provides a simple command-line interface and it is easily integrated with a lot of programming languages and tools.</li>
</ul>
<h2>Disadvantages</h2>
<p>Of course, I must list a couple of disadvantages in this MongoDB introduction, as well:</p>
<ul>
<li>Firstly, Mongo <strong>uses a MongoDB Query Language (MQL)</strong>. And although it has the same syntax as documents (which makes it really intuitive), it&#8217;s nothing universal and we have to learn it in order to work with the database. This is not the case, for example when working with SQL.</li>
<li>Moreover, <strong>MongoDB does not support joins</strong>, which we know from relational databases. And although combining documents, or collections together is still doable, it might be a bit tricky task.</li>
<li>Additionally, documents cannot <strong>exceed 16MB</strong>.</li>
<li>And lastly- <strong>data redundancy</strong>. Due to the lack of joins, we oftentimes duplicate data across the documents, which may lead to harder maintenance.</li>
</ul>
<h2>Overview Of MongoDB Use Cases</h2>
<p>With all of that said, let&#8217;s figure out when Mongo can be a good choice:</p>
<ul>
<li>And as the first one- <strong>content management</strong>. It can be used to store and manage large amounts of structured and unstructured content, thanks to its flexibility.</li>
<li>Secondly, the <strong>Internet of Things</strong>. MongoDB is a popular choice for storing and processing large amounts of data generated by IoT devices. Mongo is not only great at dealing with large amounts of data but also can handle semi-structured and unstructured data sent by IoT devices.</li>
<li>Additionally-<strong> e-commerce and recommendation systems</strong>. A flexible schema allows for easy storage of various types of product data, like prices, descriptions, etc. Moreover, MongoDB support for complex queries and aggregations can help easily create search engines and recommendation systems</li>
<li>And as the last one, a bit more general- <strong>real-time applications</strong>. MongoDB&#8217;s low latency and high performance make it a great choice for any real-time application, like social media for instance.</li>
</ul>
<h2>Which Companies Use MongoDB?</h2>
<p>And as the last thing in our MongoDB overview, let&#8217;s figure out which companies are using it in their technology stack.</p>
<p><strong>eBay</strong> uses MongoDB to store information on items for sale and to power the search functionality. Additionally, Mongo is used to store data about users&#8217; browsing and buying history, which is then used for personalization purposes.</p>
<p>Another great example is <strong>Vodafone</strong>, which uses it for IoT, new 5G innovations, and cloud-native apps.</p>
<p>Moreover, <strong>Uber</strong> makes use of Mongo to store and manage data related to its operations, such as information on drivers, riders, and rides.</p>
<p>Of course, the list is much longer and contains over 35,000 customers, like Forbes, MetLife, <a href="https://be.elementor.com/visit/?bta=206789&amp;nci=5383">Elementor</a>, and <a href="https://go.fiverr.com/visit/?bta=631764&amp;brand=fiverrhybrid">Fiverr</a>.</p>
<h2>MongoDB Overview &#8211; Summary</h2>
<p>And that&#8217;s all for this <strong>MongoDB overview</strong>. I hope that you enjoyed this introduction and if that&#8217;s the case, then <strong>please let me know in the comments</strong> 🙂</p>
<p>Of course, if you&#8217;d like to expand your knowledge of MongoDB in practice, then check out my other resources:</p>
<ul>
<li><a href="https://codersee.com/courses/rest-api-with-micronaut-kotlin-and-mongodb-course/">REST API With Micronaut, Kotlin, and MongoDB Course</a></li>
<li><a href="https://blog.codersee.com/a-guide-to-ktor-with-mongodb/">A Guide To Ktor With MongoDB</a></li>
<li><a href="https://blog.codersee.com/spring-boot-mongodb-rest-api-crud-with-kotlin/">Spring Boot MongoDB REST API CRUD with Kotlin</a></li>
</ul>
<p>Thank you and see you in the next articles!</p>
<p>The post <a href="https://blog.codersee.com/mongodb-overview-introduction-to-the-most-popular-nosql-db/">MongoDB Overview. Introduction To The Most Popular NoSQL DB</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/mongodb-overview-introduction-to-the-most-popular-nosql-db/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>A Quick Introduction To PostgreSQL</title>
		<link>https://blog.codersee.com/discover-postgresql-comprehensive-introduction/</link>
					<comments>https://blog.codersee.com/discover-postgresql-comprehensive-introduction/#respond</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Tue, 03 Jan 2023 08:15:06 +0000</pubDate>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=5504141</guid>

					<description><![CDATA[<p>In this PostgreSQL introduction, we'll cover its gensis, key features, benefits and all the necessary things we should remember about.</p>
<p>The post <a href="https://blog.codersee.com/discover-postgresql-comprehensive-introduction/">A Quick Introduction To PostgreSQL</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, I will provide you with a <strong>beginner-friendly introduction to PostgreSQL</strong>. Together, we will see what exactly PostgreSQL is and learn more about its:</p>
<ul>
<li>history,</li>
<li>key features,</li>
<li>pros &amp; cons,</li>
<li>use cases,</li>
<li>and finally- examples of companies relying on this relational database.</li>
</ul>
<p>And a friendly reminder- this PostgreSQL introduction is a continuation of a <strong>top 8 databases series</strong> I covered <a href="https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/" target="_blank" rel="noopener">here</a>.</p>
<h2>Explainer Animation</h2>
<p>If you enjoy <strong>whiteboard animations</strong>, then right here you can find a video version of this article:</p>
<div style="text-align: center; width: 80%; margin-left: 10%;">
<a href="https://blog.codersee.com/discover-postgresql-comprehensive-introduction/"><img decoding="async" src="https://blog.codersee.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2Fwo3Jo47LFAc%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></p>
</div>
<p>If you find this content useful,<strong> please leave a subscription </strong> 😉</p>
<h2>PostgreSQL History</h2>
<p>As usual, let&#8217;s start everything by learning more about PostgreSQL genesis.</p>
<p>PostgreSQL history started in the 1980s at the University of California, Berkeley when Michael Stonebraker began working on a new project, which would be the successor of Ingres. The goal of this project was to address the problems plaguing the databases of that time.</p>
<p>Initially, the project was called <strong>POSTGRES</strong>, highlighting that it is the successor of <strong>Ingres</strong> (which was created at the same university). But then, in 1996, the name was changed to PostgreSQL to emphasize its support for SQL. In 2007, the developer team decided to stick with the name PostgreSQL and Postgres as an alias.</p>
<p>But back to the development topic, the project target was to introduce support for data types and relationships between them. And, although the team took a lot of ideas from Ingres, the codebase was created from scratch.</p>
<p>The PostgreSQL introduction took place in 1986 when the team released official papers describing the system. Two years later, they performed a demo of a prototype at the ACM SIGMOD Conference. The team was gradually releasing new versions with new features and changes. Nevertheless, the number of feature requests and users began to surpass them, and the project ended in 1994, and POSTGRES Version 4.2 was released under the MIT license.</p>
<p>As the official date of the PostgreSQL release, we take <strong>8th July of 1996</strong>, when Marc Fournier created the first non-university server for Postgres development.</p>
<h2>What Is PostgreSQL Then?</h2>
<p>So, with all of that being said, let&#8217;s answer the question- what is PostgreSQL?</p>
<p><a href="https://codersee.com/newsletter/"><img decoding="async" class="aligncenter wp-image-3002956 size-large" src="http://blog.codersee.com/wp-content/uploads/2022/05/join_newsletter-1024x576.png" alt="Image shows two ebooks people can get for free after joining newsletter" width="800" height="419" /></a></p>
<p>Well, it&#8217;s an open-source relational database management system (aka RDBMS), based on the POSTGRES Version 4.2 (which we&#8217;ve already covered).</p>
<p>One of the key features of PostgreSQL is its support for a wide range of data types. Moreover, it also supports data types for special purposes, like arrays, JSON, and XML.</p>
<p>In addition to this, Postgres is also extendable and comes with a number of features that make it well-suited for a wide range of applications, like:</p>
<ul>
<li>transactions</li>
<li>stored procedures &amp; views</li>
<li>triggers</li>
<li>and support for complex queries.</li>
</ul>
<p>What&#8217;s worth mentioning here as well, the Postgres license lets everyone use, modify and distribute it entirely for free. Regardless of whether we do it commercially or for personal use.</p>
<h2>PostgreSQL Advantages</h2>
<p>Nextly, let&#8217;s take a while to go through the introduction of PostgreSQL&#8217;s <strong>advantages</strong>:</p>
<ul>
<li>First of all, <strong>it&#8217;s open source</strong>. Postgres usage is entirely free regardless of whether we use it commercially, or not. Whatsoever, we can always modify and adjust it to our needs. This makes PostgreSQL a great choice for everyone, who desires a high-quality DBMS at no cost.</li>
<li>Secondly, <strong>performance</strong>. It is known for its great performance, with the ability to handle large amounts of data and high levels of traffic.</li>
<li>Thirdly, PostgreSQL is <strong>community-driven</strong>. From its very beginning, Postgres is developed by many people and companies working together to deliver a high-quality solution.</li>
<li>Additionally, it has an <strong>active community</strong> and <strong>a lot of resources available online</strong>. Just like in previous articles, in this PostgresSQL introduction, I must use this argument. Tons of materials, libraries, forums, blog posts, etc. is a great advantage, which helps us incorporate it into our projects with ease. Moreover, in case of any problems we can easily find solutions on the internet, for example using <a href="https://stackoverflow.com/">StackOverflow</a>.</li>
<li>Whatsoever, Postgres<strong> supports a wide variety of programming languages</strong>. We can write SQL queries or custom functions with C or C++. Of course, we can find probably hundreds of libraries to write code with <a href="https://blog.codersee.com/tag/java/">Java</a>, <a href="https://blog.codersee.com/tag/kotlin/">Kotlin</a>, and many more.</li>
<li>Lastly, it comes with <strong>plenty of features</strong> and <strong>data types support</strong> out of the box. If you would like to learn more about its features, then I highly encourage you to visit its documentation <a href="https://www.postgresql.org/about/featurematrix/" target="_blank" rel="noopener">here</a>. Not to mention that we can always extend and customize its behavior due to its liberal licensing.</li>
</ul>
<h2>PostgreSQL Disadvantages</h2>
<p>With all of that great things being covered in our PostgreSQL introduction, let&#8217;s see its drawbacks:</p>
<ul>
<li>Firstly, it&#8217;s <strong>comparatively slower</strong> and <strong><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">it </span></span></span><span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span class="ryNqvb">is not as well supported as MySQL</span></span></span></strong> when it comes to different applications or hostings.</li>
<li>Secondly, <strong>complexity</strong>. PostgreSQL is a powerful ORDBMS, but it may require more resources and expertise to set up and manage than some other database systems.</li>
<li>Lastly, being an <strong>open-source solution</strong> means that there&#8217;s not a single organization, or a company standing behind it and it does not come with any warranty.</li>
</ul>
<h2>PostgreSQL Use Cases</h2>
<p>As the next thing, let&#8217;s see what PostgreSQL is well suited for:</p>
<ul>
<li>First of all, <strong>web-based apps</strong>. PostgreSQL with its great support for different (even complex) data types and other features can be a great solution for content management systems, e-commerce platforms, etc.</li>
<li><strong>Scientific</strong> and <strong>financial applications</strong>. Postgres is often used in apps, which require processing large amounts of data, support for data analysis, and transactions support.</li>
<li>Moreover, everywhere, where we <strong>need to process spatial data</strong>. Postgis, an extension for PostgreSQL, adds support for geographic objects allowing location queries to be run in SQL.</li>
</ul>
<p>Please keep in mind that these are not all possible use cases. And if you need a mature relational database management system, which supports various data types, complex queries, and large datasets, then PostgreSQL can be a great choice.</p>
<h2>Which Companies Use Postgres?</h2>
<p>As the last thing, let&#8217;s take a second to see the list of companies using PostgreSQL.</p>
<p>As the first one- Apple. It uses Postgres to store and manage data for a number of its internal systems, including its online store and customer support systems. They even replaced MySQL with Postgres as an embedded DB in the OS X Lion.</p>
<p>And as the next one, Instagram. Yes, a giant with over 2 billion users makes use of PostgreSQL as one of the main databases for their system.</p>
<p>Of course, the list of all companies is much longer, but let&#8217;s see a couple more:</p>
<ul>
<li>Skype</li>
<li>Yahoo</li>
<li>Spotify</li>
<li>Salesforce</li>
<li>Pinterest</li>
<li>Uber and Airbnb.</li>
</ul>
<h2>Summary Of The PostgreSQL Introduction</h2>
<p>And that&#8217;s all for this article, in which we cover what exactly PostgreSQL is. Together, we walked through its genesis, advantages, disadvantages, and use cases, as well.</p>
<p>I hope you enjoy this series about the most popular databases on my blog. Please keep in mind, that I have other articles, in which you can learn how to work with Postgres in practice, for example:</p>
<ul>
<li><a class="LinkSuggestion__Link-sc-1gewdgc-4 iyHtHS" href="https://blog.codersee.com/rest-api-ktor-ktorm-postgresql/" target="_blank" rel="noopener">REST API With Ktor, Ktorm, and PostgreSQL</a></li>
<li><a class="LinkSuggestion__Link-sc-1gewdgc-4 iyHtHS" href="https://blog.codersee.com/youtube-course-on-rest-api-with-spring-webflux-and-kotlin/" target="_blank" rel="noopener">YouTube Course On REST API With Spring WebFlux and Kotlin</a></li>
</ul>
<p>Alternatively, you might wan to check other articles in a series:</p>
<ul>
<li><a href="https://blog.codersee.com/redis-database-explained/">Redis Database Explained</a></li>
<li><a href="https://blog.codersee.com/mysql-essentials-fast-paced-introduction/">MySQL Essentials: A Fast-Paced Introduction</a></li>
</ul>
<p><strong>Finally, the task for you:</strong> please leave a comment with your thoughts or feedback in the comments section below.</p>
<p>The post <a href="https://blog.codersee.com/discover-postgresql-comprehensive-introduction/">A Quick Introduction To PostgreSQL</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/discover-postgresql-comprehensive-introduction/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MySQL Essentials: A Fast-Paced Introduction</title>
		<link>https://blog.codersee.com/mysql-essentials-fast-paced-introduction/</link>
					<comments>https://blog.codersee.com/mysql-essentials-fast-paced-introduction/#respond</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Tue, 27 Dec 2022 08:15:06 +0000</pubDate>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=5504127</guid>

					<description><![CDATA[<p>Learn the essentials of MySQL in this fast-paced introduction. Get started with its genesis, advantages, drawbacks, and best use cases.</p>
<p>The post <a href="https://blog.codersee.com/mysql-essentials-fast-paced-introduction/">MySQL Essentials: A Fast-Paced Introduction</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Are you ready to dive into the world of <strong>MySQL</strong>? Whether you&#8217;re a beginner looking to get started with this powerful open-source database, or an experienced developer looking to brush up on your skills, this MySQL introduction has something for everyone.</p>
<p>In this fast-paced intro, <strong>you&#8217;ll learn the essentials of MySQL</strong>, including its:</p>
<ul>
<li>history</li>
<li>advantages</li>
<li>disadvantages</li>
<li>use-cases</li>
<li>and companies, which successfully use it to ship their products.</li>
</ul>
<p>And one more thing before we start. This article is a continuation of a series describing the <a href="https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/">Top 8 Most Popular Databases</a>. If you would like to learn more about other solutions, then I highly recommend you bookmark that article and come back to it later.</p>
<h2>Explainer Animation</h2>
<p>If you enjoy <strong>whiteboard animations</strong>, then right here you can find a video version for this article:</p>
<p>&nbsp;</p>
<div style="text-align: center; width: 80%; margin-left: 10%;">
<a href="https://blog.codersee.com/mysql-essentials-fast-paced-introduction/"><img decoding="async" src="https://blog.codersee.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2FBMbJwvMLcnI%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></p>
</div>
<p>&nbsp;</p>
<p>If you find this content useful,<strong> please leave a subscription </strong> 😉</p>
<h2>MySQL Genesis</h2>
<p>So as the first thing in our introduction, let&#8217;s take a while to learn more about MySQL&#8217;s history.</p>
<p>MySQL was developed by a Swedish company called MySQL AB, which was founded in <strong>1995</strong> by Allan Larsson, David Axmark, and Michael Widenius. The name is a combination of Michael&#8217;s daughter&#8217;s name- <strong>My</strong>&#8211; and the abbreviation for <strong>S</strong>tructured <strong>Q</strong>uery <strong>L</strong>anguage (SQL).</p>
<p>The development began in <strong>1994</strong>, and the goal was to create a fast, reliable, and easy-to-use database system that could be used in a variety of applications. And although there were already a number of other database management systems available, many of these systems were complex to install and use, and they often required specialized skills and expertise to manage effectively. On the other hand, available open-source solutions were not as widely used as they are today, and many organizations were hesitant to adopt them due to concerns about their performance, support, and reliability.</p>
<p>&nbsp;</p>
<p><a href="https://codersee.com/newsletter/"><img decoding="async" class="aligncenter wp-image-3002956 size-large" src="http://blog.codersee.com/wp-content/uploads/2022/05/join_newsletter-1024x576.png" alt="Image shows two ebooks people can get for free after joining newsletter" width="800" height="419" /></a></p>
<p>&nbsp;</p>
<p>As a result, MySQL quickly gained popularity among developers and organizations looking for an alternative to commercial database systems. Its success helped to pave the way for other open-source database systems, and it played a significant role in the growth of the open-source software movement as a whole.</p>
<p>Lastly, it&#8217;s worth mentioning that MySQL AB was bought by Sun Microsystems, which is now an Oracle Corporation (since 2010).</p>
<h2>What Is MySQL and How Does It Work?</h2>
<p>And although the previous chapter is a great MySQL introduction, let&#8217;s learn a bit more about it.</p>
<p>If I would have to answer the question &#8220;what is MySQL?&#8221; in one sentence, then I&#8217;d say that it is an <strong>open-source relational database management system. </strong>Moreover, according to the StackOverflow Developer Survey 2022, it&#8217;s the most popular RDBMS in the world. It is fast, reliable, and easy to use, making it an attractive choice for developers and organizations of all sizes.</p>
<p>MySQL is written in C++ and C and it was initially created from <strong>mSQL</strong> (aka <strong>M</strong>ini <strong>SQL</strong>), which is provided for non-commercial use. And although it gained a new SQL interface, the API remained the same making it easy to migrate from mSQL.</p>
<p>As a relational database, MySQL stores and organizes data in <strong>tables</strong>, which are grouped into <strong>databases</strong>. Each table consists of <strong>rows</strong> and <strong>columns</strong>. <strong>Rows</strong> represent individual pieces of data, while <strong>columns</strong> represent the different attributes of that data. And in order to query and manipulate the data from the database, we can use <strong>SQL queries</strong>. When it comes to storage, MySQL stores data in memory and on disk combining together performance and durability.</p>
<p>Finally, MySQL includes a number of other tools and features that make it easier to manage the database. These include utilities for security, performance tuning, backup, and recovery.</p>
<h2>MySQL &amp; LAMP</h2>
<p>It&#8217;s worth mentioning in our MySQL introduction, that MySQL is a part of the <strong>LAMP stack</strong>.</p>
<p><b>LAMP</b> is nothing else than an acronym for a proven set of technologies developers use to build websites and web applications:</p>
<ul>
<li><strong>Linux</strong> for the operating system</li>
<li><strong>Apache</strong> HTTP Server</li>
<li><strong>MySQL</strong> for the relational database management system</li>
<li><strong>PHP/Perl/Python</strong> programming language</li>
</ul>
<p>Not to mention you&#8217;re reading this article thanks to MySQL (used by WordPress).</p>
<h2>MySQL Advantages</h2>
<p>So, at this point, we know what is MySQL and as the next step, let&#8217;s figure out what it brings to the table:</p>
<ul>
<li><strong>MySQL is easy to use.</strong> It is known for being easy to install and use. Moreover, it has a simple and intuitive interface. This makes it not only a great choice for beginners, and less experienced teams, but also can bring lower costs for many companies.</li>
<li><strong>It&#8217;s open-source with a large and active community</strong>. MySQL is the most popular database in the world. And this advantage, combined with tons of documentation, blogs, and other resources available online, speeds up its integration, management, and debugging.</li>
<li><strong>Performance</strong>. And even though it might not be the best choice for large data sets, it&#8217;s still a multi-user and multi-threaded SQL server, which can handle millions of requests per day.</li>
<li><strong>Transactions support</strong>. Transactions, are an important feature of MySQL and allow us to ensure that the database remains in a consistent state, even if one of the operations fails.</li>
<li><strong>Flexibility</strong>. Lastly, MySQL supports multiple storage engines, which allows users to choose the best storage engine for their specific needs. Additionally, it supports a wide range of programming languages, making it easy to integrate into web-based applications and other systems.</li>
</ul>
<h2>MySQL Disadvantages</h2>
<p>And as with everything, MySQL has some drawbacks, as well:</p>
<ul>
<li><strong>Scaling complexity</strong>. Although MySQL can actually handle a lot of traffic, the scaling process requires manually sharding the data across multiple servers and configuring the servers to work together.</li>
<li><strong>Lack of certain security features</strong>. MySQL does not include certain security features, such as data masking and data classification, which are available in other database management systems.</li>
<li><strong>Limited support for distributed transactions.</strong> It does not have native support for distributed transactions.</li>
<li><strong>Commercial editions might be pricey.</strong> Although the open-source version of MySQL is free, the commercial editions of MySQL are licensed and can be expensive.</li>
</ul>
<h2>MySQL Use Cases</h2>
<p>As the next thing in our MySQL introduction, let&#8217;s see when it can be a good choice:</p>
<ul>
<li><strong>Web-based applications.</strong> MySQL is often used as the database backend for web-based applications. (And as mentioned previously, it&#8217;s a part of a LAMP stack).</li>
<li><strong>E-commerce</strong>. It&#8217;s a common choice for e-commerce platforms, due to its ability to handle large amounts of data and transactions support.</li>
<li><strong>Mobile applications</strong>. MySQL might be used as the database backend for mobile applications, as well.</li>
<li><strong>Internet Of Things</strong>. It can be used to store and manage data from IoT devices, such as sensors and connected devices.</li>
</ul>
<h2>Companies Using MySQL</h2>
<p>Lastly, let&#8217;s see a couple of companies, which use MySQL Database to deliver their products and services.</p>
<p>First of all, <strong>WordPress uses MySQL as its default database management system</strong>. Without it, you wouldn&#8217;t read this article 😉</p>
<p>Moreover, <strong>GitHub</strong> uses MySQL as its core data store. <strong>BBC</strong> makes use of the MySQL InnoDB Cluster and <strong>Uber </strong>claims that MySQL engine as the low-level storage layer has allowed them to very quickly build a robust system.</p>
<p>Of course, when we look at the list, we can find other known companies, like:</p>
<ul>
<li>Spotify</li>
<li>YouTube</li>
<li>Facebook</li>
<li>Sony</li>
<li>Airbnb and many more.</li>
</ul>
<p>If you&#8217;d like to learn more about other companies, then you can check out the <a href="https://www.mysql.com/customers/" target="_blank" rel="noopener">official customers&#8217; list.</a></p>
<h2>MySQL Introduction Conclusion</h2>
<p>And that&#8217;s all for this MySQL introduction, which is a continuation of a <strong>Top 8 Databases</strong> series. Together, we learned what is MySQL, its advantages, and disadvantages, as well, as its history and use cases.</p>
<p>If you are interested in Spring Boot, then you might want to check out my other articles with MySQL in practice and others under the <a href="https://blog.codersee.com/tag/mysql/">MySQL Tag</a>.</p>
<p>Finally, as always am <strong>happy to answer any questions and hear your thoughts</strong>. See you in the comments section!</p>
<p>The post <a href="https://blog.codersee.com/mysql-essentials-fast-paced-introduction/">MySQL Essentials: A Fast-Paced Introduction</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/mysql-essentials-fast-paced-introduction/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Redis Database Explained</title>
		<link>https://blog.codersee.com/redis-database-explained/</link>
					<comments>https://blog.codersee.com/redis-database-explained/#respond</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Tue, 20 Dec 2022 08:10:18 +0000</pubDate>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Redis]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=5504104</guid>

					<description><![CDATA[<p>After reading this article, you will know precisely what exactly Redis database is, its advantages, disadvantages, as well as use-cases.</p>
<p>The post <a href="https://blog.codersee.com/redis-database-explained/">Redis Database Explained</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As the first article in a series explaining the <a href="https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/">top most popular databases</a>, let&#8217;s take a closer look at the <strong>Redis database</strong>.</p>
<p>Redis is an open-source in-memory data structure store, widely used as a cache, key-value database, and message broker. Moreover, it is oftentimes ranked as the most popular key-value database and one of the top NoSQL databases.</p>
<h2>Explainer Animation</h2>
<p>Below you can check an explainer video for this post.</p>
<p>If you find this content useful, please leave a <strong>thumb up</strong>, or a <strong>sub</strong>. This way you can help me so that I can help you 😉</p>
<p>&nbsp;</p>
<div style="text-align: center; width: 80%; margin-left: 10%;">
<a href="https://blog.codersee.com/redis-database-explained/"><img decoding="async" src="https://blog.codersee.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2FebzHJ-GO1tQ%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></p>
</div>
<h2></h2>
<h2>Redis Genesis</h2>
<p>Before we dive into the Redis database details, let&#8217;s take a minute to learn more about its history.</p>
<p>Redis was created in <em>2009</em> by <em>Salvatore Sanfilippo</em>, also known as <em>antirez</em>. Its name comes from the<em> Remote Dictionary Server</em> and was created when antirez was working on a web logs analyzer for his startup. Initially, the prototype was written in the Tcl programming language and was later converted to C. After a couple of weeks, Salvatore open-sourced the project, which quickly gained popularity due to its speed, flexibility, and ease of use.</p>
<p>In 2015, Sanfilippo founded <em>Redis Labs</em>, a company that provides support, services, and products for Redis. Nevertheless, at the moment of writing, antirez is not a maintainer anymore and the company itself is called simply Redis.</p>
<h2>How Does Redis Database Stand Out?</h2>
<p>With all of that being said, let&#8217;s learn how Redis works and what makes it different.</p>
<p>So, as mentioned above, <strong>Redis stores data in memory</strong> which makes it much faster than most DBMSs (which persist data to disk). But, does it really mean that the data are lost if the server running Redis restarts or goes down? Not exactly.</p>
<p>Redis was designed to combine ultra-fast data access and modification using in-memory storage with data persistence to disk. To prevent data loss, <strong>Redis supports writing data to disk</strong> using different storage options such as:</p>
<ul>
<li>snapshotting (by default, every max 2 seconds),</li>
<li>and append-only file (AOF) logging.</li>
</ul>
<p>So, if the server restarts, the data are simply restored to memory from the disk space.</p>
<p>It&#8217;s worth mentioning, that although the Redis database comes with support for plenty of different data structures, it does not have support for queries known from other databases. It is a key-value store and, the commands (like GET or SCAN) are rather direct instructions than queries, which leverage indexes, etc.</p>
<h2>Redis Advantages</h2>
<p>Nextly, let&#8217;s take a look at a couple of <strong>Redis advantages</strong>:</p>
<ul>
<li>First of all, <strong>speed</strong>. At this point, we shouldn&#8217;t be surprised that the performance is a huge advantage for Redis. That&#8217;s what it&#8217;s been designed for and disk-based solutions simply cannot compete with their in-memory rival.</li>
<li>Secondly, a <strong>huge and active community</strong>. And although I will use this argument pretty often in this series, we can never forget about it. A large community with a tremendous amount of materials available online has a huge impact on the ease of Redis incorporation. Time spent on searching and debugging can be significantly reduced and its excess can be used much better. Moreover, the Redis database is supported by a wide range of programming languages and comes with plenty of libraries and solutions, which we can use to make our lives easier.</li>
<li>As the next thing- <strong>data types support</strong>. Redis, as a key-value store comes with support not only for string values but also for various other data structures. We can use hashes, lists, sets, sorted sets, geospatial data, and even JSON and Graph using dedicated modules. Depending on the type of value used, Redis lets us use dedicated commands, like sets union, differences, and lists sorting.</li>
<li>Following, <strong>data persistence</strong>. And as I mentioned previously, by design, Redis combines low-latency read/write in-memory operations with data persistence. So in case, our server goes down or simply restarts, the data won&#8217;t be lost. Or technically, with the default snapshotting every 2 seconds, we&#8217;ll lose a max of 2 seconds of data.</li>
<li>Moreover, it&#8217;s <strong>easy to use</strong>. Instead of sophisticated queries, we communicate with Redis using a pretty simple command-line interface.</li>
<li>Lastly, Redis comes with <strong>many additional features</strong>, like transactions, pub/sub, or Lua scripting.</li>
</ul>
<p>&nbsp;</p>
<p><a href="https://codersee.com/newsletter/"><img loading="lazy" decoding="async" class="aligncenter wp-image-3002956 size-large" src="http://blog.codersee.com/wp-content/uploads/2022/05/join_newsletter-1024x576.png" alt="Image shows two ebooks people can get for free after joining newsletter" width="800" height="419" /></a></p>
<p>&nbsp;</p>
<h2>Redis Database Disvantages</h2>
<p>So, with all of the benefits being covered, let&#8217;s take a look at the Redis disadvantages:</p>
<ul>
<li>As the first one, it <strong>can be expensive with large datasets</strong>. And although in-memory storage gives Redis a huge performance advantage over disk-persisting databases, additional memory can be much more expensive.</li>
<li>Whatsoever, <strong>keys management</strong>. Redis is a key-value store and it is our job to define and maintain the appropriate keys structure.</li>
<li>Moreover, <strong>it is not designed for complex queries and relationships</strong>. This makes it easy to use and fast, but it can also limit the ability to model complex relationships between data.</li>
<li>Finally, it&#8217;s <strong>single-threaded</strong>. Redis is single-threaded, which means that it can only process one command at a time. This can limit its performance when dealing with a large number of concurrent requests.</li>
</ul>
<h2>Use-Cases</h2>
<p>At this point, we know what are Redis advantages and drawbacks, so let&#8217;s take a look at what can it be used for:</p>
<ul>
<li aria-level="1"><strong>Caching-</strong> Redis database can be used to store frequently accessed data in memory for fast access. It will be a great add-on everywhere, where latency matters.</li>
<li><strong>Session management-</strong> it can be used to store user session information, like preferences and login status. This can help us handle user requests much faster.</li>
<li aria-level="1"><strong>Real-time analytics-</strong> and basically this was the main use case for which Redis was brought to life. Its support for data structures allows for fast and efficient calculations of real-time metrics.</li>
<li aria-level="1"><strong>Leaderboards-</strong> thanks to the support for sorted sets it can be used for the easy ranking of items, making it well-suited for implementing leaderboards in applications.</li>
<li aria-level="1"><strong>Messaging-</strong> with pub/sub messaging, we can easily implement message queues and real-time client-server communication.</li>
<li aria-level="1"><strong>Product catalogs</strong>&#8211; lastly, it can be a great choice for product catalogs to store product information.</li>
</ul>
<h2>Which Companies Use Redis?</h2>
<p>As the last thing, let&#8217;s take a look at a couple of known companies, which use the Redis database.</p>
<p>When we look at the list of the most popular companies, that were the first to adopt Redis in their technology stack, we will see <a href="https://github.com/" target="_blank" rel="noopener">GitHub</a> and <a href="https://www.instagram.com/" target="_blank" rel="noopener">Instagram</a>.</p>
<p>Nowadays, when Redis database has a well-established position in the market and proved for many years that it can be trusted and can bring value to almost any project, it can be found on the backend of companies, like:</p>
<ul>
<li>Uber</li>
<li>Stripe</li>
<li>Twitter</li>
<li>Slack</li>
<li>Craiglist</li>
<li>Alibaba</li>
<li>and many more.</li>
</ul>
<h2>Redis Database Summary</h2>
<p>And that&#8217;s all for this article <strong>explaining what exactly the Redis database is</strong>. Together, we&#8217;ve learned more about Redis history, use cases, and advantages, as well as the disadvantages and the companies using it to deliver their products.</p>
<p>I hope you enjoy this series covering the most popular databases of 2022. If you enjoyed the content, <strong>please leave a comment in the section below</strong>.</p>
<p>Have a great day!</p>
<p>The post <a href="https://blog.codersee.com/redis-database-explained/">Redis Database Explained</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/redis-database-explained/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>A Quick Intro To The 8 Most Popular Databases</title>
		<link>https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/</link>
					<comments>https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/#comments</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Wed, 14 Dec 2022 07:00:33 +0000</pubDate>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Elasticsearch]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[Microsoft SQL Server]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Redis]]></category>
		<category><![CDATA[SQLite]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=5504084</guid>

					<description><![CDATA[<p>Data is one of the most valuable assets of the XXI century and in this article, we will take a look at the 8 most popular databases of 2022.</p>
<p>The post <a href="https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/">A Quick Intro To The 8 Most Popular Databases</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>It won&#8217;t be a surprise if I say that <strong>data is one of the most valuable assets of the XXI century</strong>. Many organizations and businesses rely on the most popular databases to store, manage and analyze their data to support their business needs.</p>
<p>In this article, we will take a look at the <strong>8 most popular databases</strong> and their key features, as well as common use cases.</p>
<p>So, no matter whether you are a database administrator, programmer, or simply would like to learn more about the different databases available, this article will provide you with all the necessary information to start with.</p>
<h2>Doodly Animation</h2>
<p>If you find this content useful, please leave a <strong>thumb up</strong>, or a <strong>sub</strong>. This way you can help me, so that I can help you 😉</p>
<p>&nbsp;</p>
<div style="text-align: center;">
<a href="https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/"><img decoding="async" src="https://blog.codersee.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2Fu81dp3igZVU%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></p>
</div>
<h2>What Does &#8220;The Most Popular Databases&#8221; Mean?</h2>
<p>Well, before we start I wanna make sure that we are on the same page when referring to the &#8220;most popular&#8221;.</p>
<p>Depending on who wrote the article, this term can have various meanings. For some, it will be the frequency of Google searches. For others, it may be data provided by the <a href="https://db-engines.com" target="_blank" rel="noopener">https://db-engines.com</a> page.</p>
<p>And for the purpose of this blog post, I decided to use the <a href="https://survey.stackoverflow.co/2022/" target="_blank" rel="noopener">Stack Overflow Developer Survey 2022 results</a>, which present, as follows:</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-5504088 size-large" src="http://blog.codersee.com/wp-content/uploads/2022/12/the_most_popular_databases_2022_so_developer_survey-1024x480.png" alt="The image is a screenshot of StackOverflow Developer Survey 2022 presenting the most popular databases: MySQL, PostgreSQL, SQLite, MongoDB, Microsoft SQL Server, Redis, MariaDB and ElasticSearch" width="800" height="375" srcset="https://blog.codersee.com/wp-content/uploads/2022/12/the_most_popular_databases_2022_so_developer_survey-1024x480.png 1024w, https://blog.codersee.com/wp-content/uploads/2022/12/the_most_popular_databases_2022_so_developer_survey-300x141.png 300w, https://blog.codersee.com/wp-content/uploads/2022/12/the_most_popular_databases_2022_so_developer_survey-768x360.png 768w, https://blog.codersee.com/wp-content/uploads/2022/12/the_most_popular_databases_2022_so_developer_survey.png 1253w" sizes="auto, (max-width: 800px) 100vw, 800px" /></p>
<p>&nbsp;</p>
<p>In the next chapters, I will walk you through each of the 8 most popular databases shortly.</p>
<p>Please keep in mind that this article is a general overview and expect that more thorough continuations will be added in the upcoming weeks 🙂</p>
<h2>MySQL Database</h2>
<p>With that being said, let&#8217;s start with the winner- <strong>MySQL</strong>.</p>
<p>It&#8217;s an open-source relational database management system (aka RDBMS). It was created in 1994 by the Swedish company <em>MySQL AB</em> (which was later acquired by <em>Sun Microsystems</em> and then by <em>Oracle Corporation</em>). Originally, it was developed as a proprietary database system but later it was open-sourced under the GNU General Public License.<br />
<a href="https://codersee.com/newsletter/"><img loading="lazy" decoding="async" class="aligncenter wp-image-3002956 size-large" src="http://blog.codersee.com/wp-content/uploads/2022/05/join_newsletter-1024x576.png" alt="Image shows two ebooks people can get for free after joining newsletter" width="800" height="419" /></a></p>
<p>&nbsp;</p>
<h3>Advantages:</h3>
<ul>
<li><strong>It&#8217;s free and open-source,</strong> so it can be a great choice for smaller companies and organizations preferring to cut costs.</li>
<li>Moreover, MySQL <strong>is widely supported by web hosting providers,</strong> which means that it can be easily integrated with web-based applications.</li>
<li>Additionally, it has a <strong>low learning curve</strong> and a <strong>simple and intuitive user interface</strong>, so it is not only a great choice for beginners but also for less experienced teams.</li>
<li>Finally, <strong>a large and active community of users and developers </strong>means a lot of online resources and support available.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>First of all, <strong>it is not designed for applications that require real-time data processing or high availability</strong>. And technically- this is not a drawback, but rather something you should be aware of.</li>
<li>Whatsoever, MySQL is <strong>hard to scale</strong> and <strong>not intended for large amounts</strong> of data.</li>
<li>Lastly, <strong>it does not have built-in support for full-text search or geospatial data and some advanced features that are available in other database systems.</strong></li>
</ul>
<p>As I mentioned above, I will create a separate blog post about the king of the most popular databases. But for now, I can invite you to check out my other how-to guides with MySQL:</p>
<ul>
<li><a href="https://blog.codersee.com/deploy-kotlin-spring-boot-app-with-mysql-on-kubernetes/">Deploy Kotlin Spring Boot App with MySQL on Kubernetes</a></li>
<li><a href="https://blog.codersee.com/spring-boot-on-google-gke-with-cloud-sql-and-kotlin/">Spring Boot on Google GKE with Cloud SQL and Kotlin</a></li>
</ul>
<h2>PostgreSQL (aka Postgres)</h2>
<p>Nextly, let&#8217;s take a look at the second place with a 3% difference- <strong>PostgreSQL</strong> (also known as <strong>Postgres</strong>).</p>
<p>It was created in 1986 by a team of researchers at the University of California and is a <strong>powerful</strong> and <strong>open-source</strong> object-relational database management system. PostgreSQL is a highly popular and widely used DBMS, known for its flexibility, reliability, and performance.</p>
<h3>Advantages:</h3>
<ul>
<li>Just like MySQL, PostgreSQL is <strong>open-source</strong>, <strong>free to use, </strong>and<strong> has a large, active community.</strong></li>
<li>It is <strong>highly reliable</strong> and <strong>performs well even under heavy workloads</strong>. This makes it a good choice for applications that require high availability and scalability.</li>
<li>Moreover, Postgres comes with <strong>support for a lot of features and capabilities </strong>out of the box. For example triggers, stored procedures, and multi-row transactions.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>Firstly, PostgreSQL <strong>may not be as widely supported</strong> or compatible with technologies, as some other database systems.</li>
<li>Secondly, it <strong>may not be as fast or scalable as other database management systems</strong>, such as NoSQL databases. And whereas it works well for large datasets, it is not the speed demon.</li>
<li>Whatsoever, Postgres is a pretty complex system, so <strong>it might be a bit difficult to learn</strong>.</li>
</ul>
<p>And just like previously, please expect new articles to come. But, again, if you would like to learn backend development with Kotlin and Postgres, then I can recommend:</p>
<ul>
<li><a href="https://codersee.com/courses/rest-api-with-spring-webflux-and-kotlin/">REST API With Spring WebFlux and Kotlin Course</a></li>
<li><a href="https://blog.codersee.com/tag/postgresql/">other tutorials on how to use it with Spring Boot, or Ktor</a></li>
</ul>
<h2>SQLite</h2>
<p>As the next step, let&#8217;s take a while to the no 3 in the most popular databases summary- <strong>SQLite</strong>.</p>
<p>SQLite is an embedded SQL database engine. The main difference between it and most of SQL databases is that it is self-contained and does not run a separate server process. To put it simply- it&#8217;s a library, which reads and writes directly to plain disk files.</p>
<p>It was created in 2000 by Dwayne Richard Hipp using a C programming language and since then, it become the most deployed database engine- used, among others of top web browsers.</p>
<h3>Advantages:</h3>
<ul>
<li>First of all, SQLite is a <strong>really lightweight</strong> database and it can be successfully used in low-memory environments. With all features enabled, its size can be as little as 750KiB.</li>
<li>Additionally, the database file format<strong> is portable</strong> and can be migrated between 32-bit ad 64-bit systems.</li>
<li>Moreover, SQLite is<strong> easy to learn</strong> and <strong>requires zero configuration</strong>, which makes it a great choice for beginners (and not only!)</li>
<li>Finally, it is <strong>really fast</strong> and can bring much better performance, than the filesystem.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>Firstly- it&#8217;s <strong>not suitable for client/server applications</strong>. Although it can work over the network, the filesystem latency might be an issue.</li>
<li>Secondly (and lastly), SQLite <strong>is not a good choice for high-volume websites</strong> or environments demanding<strong> high concurrency</strong>. Whereas it does not have a limit for concurrent reads, only one writer can write at any instant in time.</li>
</ul>
<h2>MongoDB (aka Mongo)</h2>
<p>And the prize for 4th place in our most popular databases ranking goes to <strong>MongoDB</strong>.</p>
<p>MongoDB is an open-source document-oriented database. It was created in 2009 by MongoDB Inc., which makes it not only the first NoSQL representative in the ranking but also the youngest one (so far). In contrast to previous examples, MongoDB is an example of a NoSQL database, so instead of <em>tables</em> and <em>rows</em>, Mongo stores JSON-like <em>documents</em>, which are organized in <em>collections</em>.</p>
<h3>Advantages:</h3>
<ul>
<li>First of all, Mongo was built with environments demanding <strong>high performance</strong> and <strong>scalability </strong>in mind.</li>
<li>Secondly, it&#8217;s <strong>flexible</strong>. MongoDB does not require you to define a schema for your collections (SQL tables counterparts), which can help you reduce the time spent on schema changes. Moreover, it can be a great choice everywhere, where a schema is hard to define.</li>
<li>Finally, just like MySQL and Postgres, MongoDB is <strong>widely supported</strong> and really <strong>easy to learn</strong>.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>No <strong>out-of-the-box support for joins</strong>. Unlike relational databases, Mongo by design does not support joins between collections, so if you have to work with highly connected data sets, then it might not be the best choice.</li>
<li>Moreover, MongoDB documents <strong>cannot exceed 16MB.</strong></li>
<li>Lastly, the lack of joins oftentimes leads to <strong>data duplication</strong>, which may become troublesome to maintain in the future.</li>
</ul>
<p>If you would like to learn Mongo in practice, then check out my <a href="https://blog.codersee.com/tag/mongodb/">practical guides about MongoDB with Spring Boot, Ktor, and Micronaut</a>.</p>
<h2>Microsoft SQL Server</h2>
<p>Following, the 5th position on the most popular databases list is taken by <strong>Microsoft SQL Server</strong>.</p>
<p>It was developed by Microsoft and first released in 1989 and is another relational database in our ranking. Microsoft SQL Server lets us communicate using T-SQL (Transact-SQL), which is an extension of SQL bringing additional features, like functions, or local variables. Whatsoever, it comes with an entire range of products, which we can optionally configure together to make it a really powerful tool.</p>
<h3>Advantages:</h3>
<ul>
<li>Firstly, Microsoft SQL Server has really <strong>good support</strong> and <strong>documentation</strong>.</li>
<li>Additionally, it&#8217;s relatively <strong>easy to set up and use</strong>.</li>
<li>Whatsoever, SQL Server provides a range of <strong>security features</strong> to protect against unauthorized access to the data and <strong>ensure data integrity</strong>.</li>
<li>Lastly, a strong point is <strong>data recovery</strong> in case anything happens.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>First of all, <strong>pricing</strong>. And although there is a free option available, Enterprise or Standard editions are pretty expensive.</li>
<li>Secondly, <strong>compatibility</strong>. Prior to the SQL Server 2017, it could be run on Windows-based servers, but this is the first version, which can be deployed on Linux.</li>
<li>Lastly, it <strong>may require additional Microsoft software purchases</strong> to fully make use of it in your case.</li>
</ul>
<h2>Redis</h2>
<p>And the 6th most popular database of 2022 is <strong>Redis</strong>.</p>
<p>It was created by Salvatore Sanfilippo, also known as antirez, in 2009, which makes it a relatively young database in our summary.</p>
<p>Redis is an open-source, in-memory data structure store that is commonly used as a database, cache, and message broker. It is known for its high performance, flexibility, and scalability, making it a popular choice for a wide range of applications. Whatsoever, it is oftentimes used in conjunction with Microservices and containers, to support the needs of modern, distributed applications.</p>
<h3>Advantages:</h3>
<ul>
<li>As the first one- Redis is an <strong>in-memory data store</strong>, which results in much higher data processing, than disk-based databases.</li>
<li>Additionally, it&#8217;s <strong>highly scalable</strong> and <strong>can be easily expanded</strong> to support the growing needs of our application.</li>
<li>Lastly, Redis is an <strong>open-source</strong> project with a<strong> large community</strong> and a<strong> huge amount of online resources</strong> to use and learn from. Moreover, <strong>it is compatible</strong> and pretty<strong> easy to use with most of the popular frameworks</strong>.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>So the first advantage is the disadvantage, as well. The in-memory data store is actually faster, but we have to keep in mind that it is <strong>more expensive</strong>.</li>
<li>Moreover, it is a key-value store (like a dictionary), which means that the application(s) connecting to Redis <strong>have to be aware of the structure</strong>, which requires additional config.</li>
<li>Lastly, Redis is doing fine when dealing with key-based operations, but <strong>is not that efficient, when it comes to searching through the data set</strong>.</li>
</ul>
<p>If you would like to learn more about it in detail, then check out my more detailed article: <a href="https://blog.codersee.com/redis-database-explained/">Redis Database Explained</a></p>
<h2>MariaDB</h2>
<p>As the one before last in the most popular databases list, let&#8217;s see what exactly <strong>MariaDB</strong> is.</p>
<p>First of all, MariaDB is a fork of the MySQL DBMS, created by the original developers of MySQL in response to the acquisition of MySQL by Oracle Corporation. The acquisition raised concerns among many users and developers about the future direction of the MySQL project, which resulted in MariaDB being released in 2009.</p>
<p>It&#8217;s known for its performance, reliability, and ease of use, and is used by many organizations around the world. Moreover, it is designed to be backward-compatible with MySQL and can be used as a drop-in replacement for it in most cases.</p>
<h3>Advantages:</h3>
<ul>
<li>Firstly, MariaDB is known for its <strong>performance</strong> and <strong>reliability</strong>.</li>
<li>Additionally, it is an<strong> open-source</strong> project with a <strong>large</strong> and <strong>active community</strong> of users and developers. And I know that this argument repeats often in this article. But trust me- a wealth of resources, such as documentation and tutorials, available online comes with plenty of other perks.</li>
<li>Thirdly, as mentioned above <strong>it can be used as a MySQL drop-in replacement in most cases</strong>. This allows companies to replace the database without changing the other tools. However, please remember that this is not always the case and sometimes may require additional work.</li>
<li>And lastly, it is <strong>widely supported</strong> by various programming languages and frameworks.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>As the first one, <strong>some of the MySQL Enterprise Edition features are not available out of the box</strong>. And although this can be done through plugins, this is an additional, independent tool we have to incorporate.</li>
<li>Whatsoever, <strong>migrating from MySQL may result in additional adjustments and config</strong>.</li>
<li>And as the last thing- <strong>the support may be pretty expensive</strong>.</li>
</ul>
<h2>Elasticsearch</h2>
<p>And finally, we come to the last position in the top 8 most popular databases of 2022- <strong>Elasticsearch</strong>.</p>
<p>Elasticsearch is an open-source, full-text search and analytics engine created by Shay Banon in 2010.</p>
<p>It is designed to be scalable and flexible, making it a popular choice for building search and data analysis applications. Moreover, it&#8217;s based on the Lucene search engine library and provides a RESTful API for interacting with the data. Elasticsearch is known for its powerful search and analytics capabilities, and can be used to search, analyze, and visualize data from a variety of sources, including structured, unstructured, and time-series data.</p>
<h3>Advantages:</h3>
<ul>
<li>Elasticsearch is an <strong>open-source</strong> project, supported by a<strong> large and active community of users</strong>.</li>
<li>Similarly, it&#8217;s <strong>compatible with plenty of programming languages and frameworks</strong>, which helps in its implementation.</li>
<li>Lastly, it is a <strong>highly scalable search and analytics engine</strong>, which is intended for fast full-text searches. Thus, it can be a great solution for website searches.</li>
</ul>
<h3>Disadvantages:</h3>
<ul>
<li>Elasticsearch <strong>may not be as fast or efficient as some other search and analytics platforms</strong> in certain scenarios- for example, a large amount of data.</li>
<li>Moreover, it <strong>is more difficult to learn</strong> compared to similar tools. But this comes with being more powerful, as well.</li>
<li>Lastly, Elasticsearch <strong>should not be used as primary storage</strong>.</li>
</ul>
<h2>The Most Popular Databases Summary</h2>
<p>And that&#8217;s all for this article about the 8 most popular databases. As I already mentioned, this is the initial, bird&#8217;s-eye view post and you can expect more detailed articles to come.</p>
<p>Let me know your thoughts in the comments section below!</p>
<p>The post <a href="https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/">A Quick Intro To The 8 Most Popular Databases</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/a-quick-intro-to-8-most-popular-databases/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Add Flyway To An Existing Spring Boot Project</title>
		<link>https://blog.codersee.com/add-flyway-to-existing-spring-boot-project/</link>
					<comments>https://blog.codersee.com/add-flyway-to-existing-spring-boot-project/#respond</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Thu, 08 Dec 2022 18:16:48 +0000</pubDate>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Flyway]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Spring Boot]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=5504025</guid>

					<description><![CDATA[<p>In this, the third article about Flyway on my blog, we will see how to add Flyway to an existing Spring Boot project. </p>
<p>The post <a href="https://blog.codersee.com/add-flyway-to-existing-spring-boot-project/">Add Flyway To An Existing Spring Boot Project</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2 class="article-heading-introduction">1. Introduction</h2>
<p>In this article, which is a continuation of a <a href="https://flywaydb.org/" target="_blank" rel="noopener">Flyway</a> series we will learn how to <strong>add Flyway to an existing Spring Boot Project</strong>.</p>
<p>If you are not sure what this tool can bring to your project, then check out my first post on <a href="https://blog.codersee.com/flyway-migrations-with-spring-boot/">Flyway with Spring Boot</a>, where you can find all the necessary information.</p>
<h2 class="article-heading-introduction">2. Project Setup</h2>
<p>This time, we won&#8217;t spend time preparing a sample project (well, if you are here then there&#8217;s a 95% chance that you already have some project).</p>
<p>Nevertheless, if you don&#8217;t have one, but still would like to learn how to add a flyway to an existing Spring Boot project, then no worries. You can find an example project in<a href="https://github.com/codersee-blog/spring-boot-add-flyway-to-existing-project" target="_blank" rel="noopener"> this GitHub repository</a>.</p>
<blockquote><p><strong>Note: </strong>If you use the project from the linked repository, then please run the script.sql file (can be found in /resources/sql directory) against your database, before you start the application.</p></blockquote>
<h2 class="article-heading-introduction">3. Strategy For Adding Flyway To Existing Spring Boot Project</h2>
<p>Before we start anything, I just wanted to emphasize that <strong>we should always create a backup, before performing any operations on our databases</strong>. Regardless of how widely used, or well-tested the tool is, something can always go wrong and we have to be ready to roll out plan B.</p>
<h3 class="article-heading-introduction">3.1 Add Flyway Dependency</h3>
<p>As the first thing (after the backup!), let&#8217;s add the necessary dependency to our Spring Boot project.</p>
<p>For gradle, it will look as follows:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="groovy">implementation 'org.flywaydb:flyway-core:9.8.3'</pre>
<p>On the other hand, when working with Maven, we need to add these lines:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="xml">&lt;dependency&gt;
  &lt;groupId&gt;org.flywaydb&lt;/groupId&gt;
  &lt;artifactId&gt;flyway-core&lt;/artifactId&gt;
  &lt;version&gt;9.8.3&lt;/version&gt;
&lt;/dependency&gt;</pre>
<h3 class="article-heading-introduction">3.2 Verify Spring Boot App</h3>
<p>Nextly, let&#8217;s run our Spring Boot application and verify, whether anything changed:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Found non-empty schema(s) "custom_schema" but no schema history table. Use baseline() or set baselineOnMigrate to true to initialize the schema history table.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1751) ~[spring-beans-6.0.2.jar:6.0.2]</pre>
<p>As we can clearly see, Flyway throws a pretty descriptive message:</p>
<blockquote><p>Found non-empty schema(s) &#8220;custom_schema&#8221; but no schema history table. Use baseline() or set baselineOnMigrate to true to initialize the schema history table.</p></blockquote>
<p>And basically, this error clearly states what we need to do when adding a Flyway to an existing project. But before that, we have to take care of a couple of things.</p>
<h3 class="article-heading-introduction">3.3 Generate Production Database DDL</h3>
<p>Firstly, we have to generate an <strong>SQL script containing the DDL our production database</strong>, including:</p>
<ul>
<li>procedures</li>
<li>views,</li>
<li>triggers etc&#8230;</li>
</ul>
<p>I won&#8217;t go into details here, because DDL script generation depends on the database you are using. Nevertheless, it can be done pretty easily with tools like <em>DataGrip</em>, <em>DBeaver</em>, or <em>pg_dump</em>.<br />
<a href="https://codersee.com/newsletter/"><img loading="lazy" decoding="async" class="aligncenter wp-image-3002956 size-large" src="http://blog.codersee.com/wp-content/uploads/2022/05/join_newsletter-1024x576.png" alt="Image shows two ebooks people can get for free after joining newsletter" width="800" height="419" /></a></p>
<p>And when the SQL script with DDL is ready, let&#8217;s save it in the Flyway migrations directory (in Spring Boot the default one is <em>resources/db/migration)</em>. Of course, we have to remember about the Flyway files naming convention, so the file name should be something, like <em>V1__my_custom_init_script.sql</em>.</p>
<h3 class="article-heading-introduction">3.4 Clear Irrelevant Data</h3>
<p>If you have only one database instance in your project, then feel free to skip this point. Otherwise,<strong> we have to make sure that the generated DDL script will work in every other environment</strong>. And we can achieve it in two ways:</p>
<ul>
<li><strong>if we don&#8217;t care about the data</strong> in other environments- then we can run the Flyway <em>clean</em> command.</li>
<li>however, <strong>if we do actually care about the data</strong> in our non-production environments, then there&#8217;s no other choice than to manually verify and align other database structures with the main one.</li>
</ul>
<p>The choice here is yours and will depend on many factors, like the importance of test data, amount of environments, etc.</p>
<p>Nevertheless, if you would like to clean your database before adding a Flyway to your existing project, then you can do that with the following:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">flyway -defaultSchema="custom_schema" \
  -url="jdbc:postgresql://{URL}:{PORT}/{DB_NAME}" \
  -cleanDisabled="false" \
  -user="{USERNAME}" \
  clean</pre>
<p>Please keep in mind that with this command, we will be prompted to enter the password manually (and alternatively, we can pass the <em>-password</em> flag).</p>
<h3 class="article-heading-introduction">3.5 Add Flyway To Existing Spring Boot Project</h3>
<p>Finally, with all that being done, we can return to the Spring Boot project and make the necessary changes.</p>
<p>Let&#8217;s navigate to the <strong>application.yaml</strong> file and insert these settings:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">spring:
  flyway:
    baselineOnMigrate: true
    defaultSchema: "custom_schema" # not necessary, but most likely you'll want to point to a specific schema</pre>
<p>As we can see, with <strong>baselineOnMigrate</strong> set to true, we instruct Flyway to <strong>automatically call baseline when migration is executed against a non-empty schema</strong>. Additionally, we set the <strong>defaultSchema</strong> value, but this is totally optional.</p>
<p>As a result, the <strong>flyway_schema_history</strong> table is added to our schema:</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-5504072 size-full" src="http://blog.codersee.com/wp-content/uploads/2022/12/flyway_schema_history_table_structure.png" alt="Image presents screenshot with flyway_schema_history table structure, which was added when we add Flyway to existing Spring Boot project." width="837" height="218" srcset="https://blog.codersee.com/wp-content/uploads/2022/12/flyway_schema_history_table_structure.png 837w, https://blog.codersee.com/wp-content/uploads/2022/12/flyway_schema_history_table_structure-300x78.png 300w, https://blog.codersee.com/wp-content/uploads/2022/12/flyway_schema_history_table_structure-768x200.png 768w" sizes="auto, (max-width: 837px) 100vw, 837px" /></p>
<p>and populated with <strong>precisely one record</strong>.</p>
<p>Please remember that the <strong>baselineOnMigrate set to true is only required once- when we do the initial deployment</strong> and can be removed after that.</p>
<h3 class="article-heading-introduction">3.6 Add Flyway Using Commands</h3>
<p>Basically, with all of the above being done we are finished and can enjoy the benefits of Flyway in our project.</p>
<p>However, if you would like to learn how to add Flyway to an existing project using CLI, then you can do exactly the same with the following command:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">flyway -defaultSchema="custom_schema" \ 
-url="jdbc:postgresql://{HOST}:{PORT}/{DB_NAME}" \
-user="USERNAME" \
-baselineOnMigrate="true" \
-locations="filesystem:." migrate</pre>
<p>Or, alternatively<strong>, run baseline only: </strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">flyway -defaultSchema="custom_schema" \ 
-url="jdbc:postgresql://{HOST}:{PORT}/{DB_NAME}" \
-user="USERNAME" \
-locations="filesystem:." baseline</pre>
<p>And then <strong>the migrate command</strong>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="raw">flyway -defaultSchema="custom_schema" \ 
-url="jdbc:postgresql://{HOST}:{PORT}/{DB_NAME}" \
-user="USERNAME" \
-locations="filesystem:." migrate</pre>
<p>These commands might be useful if you would like to extract migrations to a separate directory (and/or repository).</p>
<h2>4. Add Flyway To An Existing Spring Boot Project Summary</h2>
<p>And that would be all in this article about how to add Flyway to an existing Spring Boot project. If you&#8217;d like to get to know Flyway better, then I highly encourage you to visit <a href="https://flywaydb.org/documentation/" target="_blank" rel="noopener">their documentation</a>.</p>
<p>Let me know in the comments section in case of any questions 🙂</p>
<p>The post <a href="https://blog.codersee.com/add-flyway-to-existing-spring-boot-project/">Add Flyway To An Existing Spring Boot Project</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/add-flyway-to-existing-spring-boot-project/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Flyway Migrations With Spring WebFlux (R2DBC)</title>
		<link>https://blog.codersee.com/flyway-spring-webflux/</link>
					<comments>https://blog.codersee.com/flyway-spring-webflux/#comments</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Tue, 31 May 2022 05:41:27 +0000</pubDate>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Flyway]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Spring Boot]]></category>
		<category><![CDATA[Spring WebFlux]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=2502876</guid>

					<description><![CDATA[<p>In this article I will show you how to configure Flyway migrations when working with Spring WebFlux and Spring Data R2DBC.</p>
<p>The post <a href="https://blog.codersee.com/flyway-spring-webflux/">Flyway Migrations With Spring WebFlux (R2DBC)</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2 class="article-heading-introduction">1. Introduction</h2>
<p>In this short article, I would like to show you how to configure <strong>Flyway</strong> when working with<strong> Spring WebFlux and Spring Data R2DBC</strong>.</p>
<p>In my <a href="https://blog.codersee.com/flyway-migrations-with-spring-boot/" target="_blank" rel="noopener">previous tutorial</a>, we&#8217;ve learned a lot about Flyway itself and how to set it up correctly, when working with Spring Boot. Nevertheless, if we would like to apply this knowledge when building a reactive web application with Spring WebFlux and Spring Data R2DBC, we would have to take a different approach. And that&#8217;s what we are going to focus on in this tutorial.</p>
<h2 class="article-heading-introduction">2. Imports</h2>
<h3 class="article-heading-introduction">2.1. Create Spring WebFlux With R2DBC Project</h3>
<p>As the first step, let&#8217;s create a skeleton project. We can do so by simply going to the <a href="https://start.spring.io/" target="_blank" rel="noopener">Spring Initializr</a> page and selecting the following dependencies:</p>
<ul>
<li>Spring Reactive Web</li>
<li>Spring Data R2DBC</li>
<li>PostgreSQL Driver</li>
</ul>
<p>After that, we should see the following in our <code class="EnlighterJSRAW" data-enlighter-language="kotlin">build.gradle.kts</code> file:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="kotlin">implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
runtimeOnly("org.postgresql:postgresql")
runtimeOnly("org.postgresql:r2dbc-postgresql")

// other dependencies</pre>
<h3 class="article-heading-introduction">2.2. Add Flyway Dependency</h3>
<p>Unfortunately, we can&#8217;t add the Flyway dependency to our Spring WebFlux project on the same page, so we have to do it manually:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="kotlin">implementation("org.flywaydb:flyway-core:8.5.11")</pre>
<p>With that being done, we have to reload Gradle changes and wait till the additional dependency is fetched to our environment.</p>
<p>&nbsp;</p>
<p><a href="https://codersee.com/newsletter/"><img loading="lazy" decoding="async" class="aligncenter wp-image-3002956 size-large" src="http://blog.codersee.com/wp-content/uploads/2022/05/join_newsletter-1024x576.png" alt="Image shows two ebooks people can get for free after joining newsletter" width="800" height="419" /></a></p>
<p>&nbsp;</p>
<h2 class="article-heading-introduction">3. Configure application.properties (or YAML) File</h2>
<p>As the next step, let&#8217;s head to the <code class="EnlighterJSRAW" data-enlighter-language="kotlin">application.properties</code> file (or <code class="EnlighterJSRAW" data-enlighter-language="kotlin">application.yaml</code> in my case) and configure database connection along with Flyway:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="yaml">spring:
  r2dbc:
    url: r2dbc:postgresql://localhost:5432/
    username: postgres
    password: password
  flyway:
    url: jdbc:postgresql://localhost:5432/
    user: postgres
    password: password</pre>
<p>Please keep in mind that the values used for port, username, and password may be different in your case. Moreover, in the case of the Flyway connection, we have to use <strong>JDBC</strong>.</p>
<h2 class="article-heading-introduction">4. Implement Flyway Migration</h2>
<p>Nextly, let&#8217;s prepare an SQL file, which we would like to run as the first migration. Let&#8217;s call it <strong>V1__My_First_Migration.sql</strong>:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">CREATE TABLE person(
  id SERIAL NOT NULL PRIMARY KEY,
  email TEXT NOT NULL
);</pre>
<p>As we can see, this simple script will create a new table called <code class="EnlighterJSRAW" data-enlighter-language="raw">person</code>. Please remember to put this file in the correct directory-<strong> resources/db/migration/</strong> in our case.</p>
<h2 class="article-heading-introduction">5. Add Flyway Configuration For R2DBC</h2>
<p>As the next step, let&#8217;s run our application to see if our Flyway migration is working. Technically, the app started successfully. Nevertheless, logs do not contain anything about applied migration and when we check the database we can clearly see, that <strong>migration was not run</strong>.</p>
<p>To change that, let&#8217;s add a <code class="EnlighterJSRAW" data-enlighter-language="kotlin">FlywayConfiguration</code> file to our project:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="kotlin">@Configuration
class FlywayConfiguration(private val env: Environment) {

    @Bean(initMethod = "migrate")
    fun flyway(): Flyway {
        return Flyway(Flyway.configure()
            .dataSource(
                env.getRequiredProperty("spring.flyway.url"),
                env.getRequiredProperty("spring.flyway.user"),
                env.getRequiredProperty("spring.flyway.password"))
        )
    }
}</pre>
<p>Alternatively, we can use <code class="EnlighterJSRAW" data-enlighter-language="kotlin">@Value</code> annotation, as well:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="kotlin">@Configuration
class FlywayConfiguration(
    @Value("\${spring.flyway.url}") private val url: String,
    @Value("\${spring.flyway.user}") private val user: String,
    @Value("\${spring.flyway.password}") private val password: String
) {

    @Bean(initMethod = "migrate")
    fun flyway(): Flyway {
        return Flyway(
            Flyway.configure()
                .dataSource(url, user, password)
        )
    }
}</pre>
<p>As we can see, this configuration is responsible for creating a new Flyway bean with the URL, username, and password obtained from our <code class="EnlighterJSRAW" data-enlighter-language="kotlin">application.yaml</code> file.</p>
<p>If we rerun our app once again, we will see the following:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">Creating Schema History table "public"."flyway_schema_history" ...
Current version of schema "public": &lt;&lt; Empty Schema &gt;&gt;
Migrating schema "public" to version "1 - My First Migration"
Successfully applied 1 migration to schema "public", now at version v1 (execution time 00:00.034s)</pre>
<p>The above message clearly indicates that the migration was run and we can expect a new table in our database.</p>
<h2 class="article-heading-introduction">6. Summary</h2>
<p>And that would be all for this short article on how to configure <strong>Flyway migrations with Spring WebFlux and R2DBC</strong>.</p>
<p>Let me know if you found this material useful in the comment sections below, or by using the <a href="https://codersee.com/contact/" target="_blank" rel="noopener">contact form</a>.</p>
<p>Finally, if you would like to see the whole source code, please refer to this <a href="https://github.com/codersee-blog/spring-webflux-flyway" target="_blank" rel="noopener">GitHub repository</a>.</p>
<p>The post <a href="https://blog.codersee.com/flyway-spring-webflux/">Flyway Migrations With Spring WebFlux (R2DBC)</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/flyway-spring-webflux/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Flyway Migrations With Spring Boot</title>
		<link>https://blog.codersee.com/flyway-migrations-with-spring-boot/</link>
					<comments>https://blog.codersee.com/flyway-migrations-with-spring-boot/#respond</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Mon, 23 May 2022 06:00:21 +0000</pubDate>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Flyway]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Spring Boot]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=2502844</guid>

					<description><![CDATA[<p>In this tutorial, we will learn what exactly Flyway is and how we can configure it when working with Spring Boot.</p>
<p>The post <a href="https://blog.codersee.com/flyway-migrations-with-spring-boot/">Flyway Migrations With Spring Boot</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading" id="h-1-introduction">1. Introduction</h2>



<p>In this blog post, I would like to show you what exactly <a href="https://flywaydb.org/" target="_blank" rel="noopener">Flyway</a> is and how to configure it, when working with<strong> Spring Boot.</strong></p>



<p>Together, we will spend some time to figure out:</p>



<ul class="wp-block-list">
<li>why do we even need it in our project?</li>



<li>how can we quickly configure Flyway with Spring Boot?</li>



<li>finally, how can we customize its behavior?</li>
</ul>



<h2 class="wp-block-heading" id="h-2-what-is-flyway-and-what-problems-does-it-solve">2. What is Flyway and What Problems Does It Solve?</h2>



<p>To put it simply, Flyway is a <strong>database versioning tool</strong>. Just like Git is a version control system for our codebase, Flyway takes care of<strong> database schema management</strong>.</p>



<p>Let&#8217;s imagine that we&#8217;ve started a Spring Boot project, which communicates with the PostgreSQL database. We&#8217;ve been working on our own, implementing new features, adding new tables, and changing the schema many times. At some point, a new programmer joins our team, so we simply export our local or remote database and send him the script, so that he will be able to set up a local environment.</p>



<p>So far so good, but what will happen when more people join our team? Or we would like to create more testing environments? Of course, we could save the script and update it each time, we change anything, but this can introduce plenty of problems, for example:</p>



<ul class="wp-block-list">
<li>when multiple people are editing schema asynchronously, how can we make sure that all their scripts are applied in a specific environment?</li>



<li>how can we be sure that all developers have exactly the same (or a specific) version on their local?</li>



<li>how can we determine the correct order of scripts, so that nothing breaks when applying them?</li>
</ul>



<p>If you are not convinced after reading the above points, then imagine working without Git when cooperating with others and exchanging written code manually 🙂 Technically- doable- nevertheless definitely not recommended.</p>



<p>Of course, Flyway is not the only tool we could use with Spring Boot, however, it is definitely<strong> easy to work with</strong>.</p>


<p>[elementor-template id=&#8221;9007393&#8243;]</p>



<h2 class="wp-block-heading" id="h-3-setup-flyway-with-spring-boot">3. Setup Flyway With Spring Boot</h2>



<p>With all of that being said, let&#8217;s switch to the practice part. If you would like to simply download the skeleton for this tutorial, I&#8217;ve uploaded it to <a href="https://github.com/codersee-blog/spring-boot-flyway-skeleton" target="_blank" rel="noopener">this GitHub repository</a>. Nevertheless, I highly encourage you to set up the Spring Boot project on your own and follow below steps. This way, you&#8217;re definitely gonna learn more.</p>



<h3 class="wp-block-heading" id="h-3-1-imports">3.1. Imports</h3>



<p>As the first step, let&#8217;s add the necessary imports:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="kotlin" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">implementation("org.flywaydb:flyway-core:10.13.0")
runtimeOnly("org.flywaydb:flyway-database-postgresql:10.13.0")
implementation("org.postgresql:postgresql:42.7.3")
implementation("org.springframework.boot:spring-boot-starter-data-jdbc") //alternatively, we could use spring-boot-starter-data-jpa</pre>



<p>The above 4 are the bare minimum required to work with Flyway and Spring Boot.</p>



<h3 class="wp-block-heading" id="h-3-2-edit-application-properties">3.2. Edit Application Properties</h3>



<p>As the next step, we have to make sure that we&#8217;ve set up the database connection properly.</p>



<p>The easiest way to do so is via <strong>application.yaml</strong> (or <strong>application.properties</strong>) file:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="kotlin" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">spring:
  datasource:
    url: "jdbc:postgresql://localhost:5432/your-db-name"
    username: db-username
    password: db-password</pre>



<p>By default, Flyway will use the <strong>@Primary Data Source</strong> (which we&#8217;ve configured above).</p>



<h3 class="wp-block-heading" id="h-3-3-add-migrations-directory">3.3. Add Migrations Directory</h3>



<p>Nextly, we have to add <strong>/db/migration</strong> directory to the <strong>/resources</strong>. If we don&#8217;t do so and try to run the application, it will fail with the following error:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Flyway failed to initialize: none of the following migration scripts locations could be found:</p>
</blockquote>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>classpath:db/migration</p>
</blockquote>



<p>Of course, we can customize that, and we will learn how to do that later.</p>



<h3 class="wp-block-heading" id="h-3-4-validation">3.4. Validation</h3>



<p>For now, let&#8217;s check if our setup is working correctly (please make sure that you have a database with an empty schema <strong>up and running</strong>).</p>



<p>After we run the application, we should see the following in the logs:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Flyway Community Edition 8.5.11 by Redgate
...
Successfully validated 0 migrations (execution time 00:00.009s)
No migrations found. Are your locations set up correctly?
Creating Schema History table "public"."flyway_schema_history" ...
Schema "public" is up to date. No migration necessary.
</pre>



<p>Moreover, we can see that a new table called <strong>flyway_schema_history</strong> was added to our schema.</p>



<p>In brief, Flyway uses this table to manage versions and control applied, modified or added scripts. If you would like to see more theory, then <a href="https://flywaydb.org/documentation/getstarted/how" target="_blank" rel="noopener">this article</a> from their documentation is a great source for that.</p>



<h3 class="wp-block-heading" id="h-3-5-add-a-migration">3.5. Add a Migration</h3>



<p>Finally, let&#8217;s add our first migration file called <strong>V1__Create_User_Table.sql</strong>. This &#8220;strange&#8221; filename is the<strong> default Flyway naming convention</strong>, which consists of:</p>



<ul class="wp-block-list">
<li><strong>a prefix</strong>&#8211; <strong>B</strong> for baseline, <strong>R</strong> for repeatable,  <strong>U</strong> for undo, and <strong>V</strong> for versioned migrations</li>



<li><strong>migration number</strong>&#8211; number <strong>1</strong> in our case. If we would like it to be <strong>1.1</strong>, then we should start the name with <strong>V1_1</strong></li>



<li><strong>double underscore</strong>&#8211; separates version from migration description</li>



<li><strong>description</strong>&#8211; underscores are translated to spaces, so our migration will become <strong>Create User Table </strong></li>
</ul>



<p>With that being said, let&#8217;s add an example SQL script:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="sql" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">CREATE TABLE IF NOT EXISTS app_user (
  id SERIAL NOT NULL PRIMARY KEY,
  name TEXT NOT NULL
);
</pre>



<p>After that, let&#8217;s run our Spring Boot application once again and check out printed logs:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Migrating schema "public" to version "1 - Create User Table"</pre>



<p>As can be seen, migration was applied successfully and a new table was added to our database.</p>



<h2 class="wp-block-heading" id="h-4-flyway-customization-with-application-properties">4. Flyway Customization With application.properties</h2>



<h3 class="wp-block-heading" id="h-4-1-enable-disable-flyway">4.1. Enable/Disable Flyway</h3>



<p>By default, Flyway is enabled when added to Spring Boot. Nevertheless, if we would like to change that, we can set the <strong>enabled</strong> flag:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="kotlin" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">spring:
  flyway:
    enabled: false</pre>



<h3 class="wp-block-heading" id="h-4-2-set-custom-migrations-directory">4.2. Set Custom Migrations Directory</h3>



<p>As I&#8217;ve mentioned earlier, the default directory is <strong>/db/migration</strong>, but it can be customized with <strong>spring.flyway.locations</strong> property:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="kotlin" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">spring:
  flyway:
    locations: "classpath:my-custom-dir,classpath:my-custom-dir-2"</pre>



<p>As we can see, we can provide multiple directories. When working with Spring Boot, a <strong>classpath</strong> means <strong>resources</strong> directory. Alternatively, we can refer to any directory in the system using <strong>filesystem</strong> instead.</p>



<p>It&#8217;s worth mentioning that when we specify multiple directories, then at least one of them has to exist (but not all of them). Moreover, we can&#8217;t duplicate migration versions among our directories.</p>



<p>So, in practice:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">/resources
    /my-custom-dir
        V2__one.sql
    /my-custom-dir-2
        V1__one.sql
</pre>



<p>These two directories are treated, just like one and if we would specify V1 version twice, then the <strong>FlywayException</strong> would be thrown:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Found more than one migration with version 1</p>
</blockquote>



<h3 class="wp-block-heading" id="h-4-3-vendor-aware-directory">4.3. Vendor Aware Directory</h3>



<p>Additionally, Flyway allows us not only to specify hard-coded paths, but we can use a <strong>vendor</strong> placeholder, which will be resolved on the fly:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="kotlin" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">spring:
  flyway:
    locations: "classpath:my-custom-dir/{vendor}"</pre>



<p>With the above config, Flyway will look for migrations files inside the <strong>/resources/my-custom-dir/postgresql</strong> directory. You can find a full list of supported vendors <a href="https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java" target="_blank" rel="noopener">right here</a>.</p>



<h2 class="wp-block-heading" id="h-5-flyway-java-kotlin-configuration">5. Flyway Java (Kotlin) Configuration</h2>



<p>It&#8217;s worth mentioning that Flyway allows us to <strong>apply migrations written in Java</strong>. When working with Spring Boot, they will be auto-configured with any bean implementing a <strong>JavaMigration</strong> interface. However, this interface requires us to implement a few methods, so the recommended way is to extend the <strong>BaseJavaMigration</strong> abstract class instead (and sufficient in most cases).</p>



<p>Given that, let&#8217;s have a look at the example written in Kotlin (which technically does not differ too much from its Java counterpart):</p>



<pre class="EnlighterJSRAW" data-enlighter-language="kotlin" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">@Component
class V1__Create_User_Table : BaseJavaMigration() {
    override fun migrate(context: Context) {
        val update = context.connection.createStatement()
        update.execute(
            """
            CREATE TABLE IF NOT EXISTS app_user (
                id SERIAL NOT NULL PRIMARY KEY, 
                name TEXT NOT NULL
            );
            """.trimIndent()
        )
    }
}

@Component
class V2__Drop_User_Table : BaseJavaMigration() {
    override fun migrate(context: Context) {
        val update = context.connection.createStatement()
        update.execute("DROP TABLE app_user;")
    }
}</pre>



<p>As we can see, the only thing we have to do is to override the <strong>migrate</strong> method, and that class names should follow the default Flyway naming convention.</p>



<p>If you are wondering whether we can <strong>mix SQL files with Spring Beans configuration</strong>, then the answer is <strong>yes</strong> (however we should be really cautious about it).</p>



<h2 class="wp-block-heading" id="h-6-flyway-with-spring-boot-summary">6. Flyway With Spring Boot Summary</h2>



<p>And that would be all for this tutorial about <strong>Flyway With Spring Boot</strong>. I believe the knowledge presented here will be sufficient to easily incorporate this tool into any <a href="https://blog.codersee.com/category/spring/" target="_blank" rel="noopener">Spring Boot</a> project. Moreover, if you&#8217;d like to learn how to incorporate Flyway to an existing Spring Boot project, or how to use it with Spring WebFlux, <strong>then check out the <a href="https://blog.codersee.com/tag/flyway/" target="_blank" rel="noopener">flyway tag</a></strong>.</p>



<p>Let me know what you think about database version control tools. Do you like Flyway, or maybe you prefer some other tool?</p>



<p>Have a great day and see you in the next articles! 🙂</p>
<p>The post <a href="https://blog.codersee.com/flyway-migrations-with-spring-boot/">Flyway Migrations With Spring Boot</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/flyway-migrations-with-spring-boot/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: blog.codersee.com @ 2026-05-12 00:11:54 by W3 Total Cache
-->