<?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/"
	 xmlns:media="http://search.yahoo.com/mrss/" >

<channel>
	<title>NoSQL &#8211; Nearshore Software Development Company &#8211; IT Outsourcing Services</title>
	<atom:link href="https://nearshore-it.eu/tag/nosql/feed/" rel="self" type="application/rss+xml" />
	<link>https://nearshore-it.eu</link>
	<description>We are Nearshore Software Development Company with 14years of experience in delivering a large scale IT projects in the areas of PHP, JAVA, .NET, BI and MDM.</description>
	<lastBuildDate>Mon, 10 Mar 2025 14:06:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>

<image>
	<url>https://nearshore-it.eu/wp-content/uploads/2023/01/cropped-inetum-favicon-300x300-1-32x32.png</url>
	<title>NoSQL &#8211; Nearshore Software Development Company &#8211; IT Outsourcing Services</title>
	<link>https://nearshore-it.eu</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>NoSQL vs SQL databases. What&#8217;s the difference? When to choose SQL database, and when NoSQL?</title>
		<link>https://nearshore-it.eu/technologies/nosql-vs-sql-differences-and-use-cases/</link>
					<comments>https://nearshore-it.eu/technologies/nosql-vs-sql-differences-and-use-cases/#respond</comments>
		
		<dc:creator><![CDATA[Piotr Rzeznik]]></dc:creator>
		<pubDate>Thu, 02 Mar 2023 13:18:58 +0000</pubDate>
				<category><![CDATA[Technologies]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[NoSQL]]></category>
		<guid isPermaLink="false">https://nearshore-it.eu/?p=22205</guid>

					<description><![CDATA[The aspect of data storage and processing large amounts of data is one of the inherent elements and challenges of any IT project. There are many types of databases and choosing between several flexible data models is not always easy – the main challenge here is to accurately and logically represent business processes of a given domain. So when and which databases use? What databases are available? What's the difference between NoSQL and SQL databases? What are the use cases? And finally – what are the capabilities of non-relational NoSQL databases?]]></description>
										<content:encoded><![CDATA[
<p></p>



<div class="table-of-contents">
    <p class="title">Go To:</p>
    <ol>
                    <li><a href="#SQL-and-NoSQL-database-types">1.  SQL and NoSQL database types</a></li>
                    <li><a href="#What-is-SQL?">2.  What is SQL?</a></li>
                    <li><a href="#What-is-a-relational-database?">3.  What is a relational database?</a></li>
                    <li><a href="#How-do-SQL-relational-databases-work">4.  How do SQL relational databases work</a></li>
                    <li><a href="#Relationship-types">5.  Relationship types</a></li>
                    <li><a href="#NoSQL-database-–-how-does-it-work?">6.  NoSQL database – how does it work?</a></li>
                    <li><a href="#Choosing-between-SQL-and-NoSQL">7.  Choosing between SQL and NoSQL</a></li>
                    <li><a href="#To-sum-up:-relational-database-or-non-relational-data-model?">8.  Summary </a></li>
            </ol>
</div>


<h2 class="wp-block-heading" id="SQL-and-NoSQL-database-types">NoSQL vs SQL database types</h2>



<p>The most popular types of databases include:</p>



<ul class="wp-block-list">
<li>relational databases (e.g. MySQL)</li>



<li>and non-relational databases (e.g. <a href="https://nearshore-it.eu/articles/technologies/mongodb-ecommerce-database/" target="_blank" rel="noreferrer noopener">MongoDB</a>, Oracle NoSQL database).</li>
</ul>



<h2 class="wp-block-heading" id="What-is-SQL?">What is SQL?</h2>



<p>SQL is nothing but a language, but its purpose is quite different from that of Java or C # languages. SQL is used for specific activities such as data access and modification. To be more specific,<strong> SQL means Structured Query Language</strong>. It is a query language that allows you to retrieve data from a database – for this purpose it was created: to access, store and edit data in relational databases.</p>



<h2 class="wp-block-heading" id="What-is-a-relational-database?">What is a relational database?</h2>



<p>A relational database is a type of database that is usually made up of tables. This allows you to access data in a relationship that is part of other data (a table) in the same database. In other words, it stores data in multiple tables that are structured into columns and rows. This allows you to query data from different tables at the same time.</p>



<p>A relational database is based on a relational model, and <strong>RDBMS (Relational Database Management System)</strong>. In order for Relational Database Management Systems to work with many kinds of databases, SQL is used for managing and creating queries, which is in this case the most popular language.</p>



<h2 class="wp-block-heading" id="How-do-SQL-relational-databases-work">How do SQL relational databases work</h2>



<p>Relational database is based on the relational model in which data is mapped to one or more tables (or “relationships”), columns and rows, which maps data to one or more tables (or “relationships”), columns and rows. Each row in the table has a unique identifier by which it is associated. In turn, each database table represents some type of entity (an example of an entity could be “customer”).</p>



<p>The rows of the table show a specific instance of this entity (e.g. customer – John Doe), and the columns, also known as attributes, show the details of a given object (e.g. name, address). The relationships themselves are nothing more than matching data in different tables on the basis of primary and foreign keys.</p>


</style><div class="promotion-box promotion-box--image-left "><div class="tiles latest-news-once"><div class="tile"><div class="tile-image"><img decoding="async" src="https://nearshore-it.eu/wp-content/uploads/2024/06/BigCTA_MarekCzachorowski.jpg" alt="BigCTA MarekCzachorowski" title="NoSQL vs SQL databases. What&#039;s the difference? When to choose SQL database, and when NoSQL? 1"></div><div class="tile-content"><p class="entry-title client-name promotion-box__headline2">Elevate Your Application Development</p>
<p class="promotion-box__description2">Our tailored Application Development services meet your unique business needs. Consult with <strong>Marek Czachorowski</strong>, Head of Data and AI Solutions, for expert guidance.</p>
<a class="btn btn-primary booking" href="https://outlook.office365.com/book/BookameetingwithMarek@gfi.fr/" target="_blank" rel="noopener">Schedule a meeting</a></div></div></div></div>



<h2 class="wp-block-heading" id="Relationship-types">Relationship types</h2>



<p>The main types of relationships are:</p>



<h3 class="wp-block-heading">1-to-1</h3>



<p>A one-to-one relationship between two tables. It occurs when each record from the first table has exactly one record from the second table assigned to it, and vice versa. To define a one-to-one relationship, include the primary key value from the first table in the second table.</p>



<h3 class="wp-block-heading">1-to-many</h3>



<p>A one-to-many relationship also exists between two tables. Occurs when a single record from the first table has one or more records from the second table associated with it. However, the second table only has one record from the first table associated with it.</p>



<h3 class="wp-block-heading">Many-to-many</h3>



<p>Many-to-many relationship – This is also the relationship between two tables. A single record from the first table has one or more records from the second table associated with it, and vice versa. In a many-to-many relationship, a third table is often created.</p>



<h2 class="wp-block-heading" id="NoSQL-database-–-how-does-it-work?">NoSQL database – how does it work?</h2>



<p><strong>Non-relational databases</strong> are also called NoSQL databases. The name comes from a different approach to storing and retrieving data than in SQL-based relational databases. Note that some non-relational databases support SQL.</p>



<p>NoSQL databases are characterized by the fact that <strong>they are able to handle a large amount of unstructured data</strong>. NoSQL solutions are nothing new, but only for several years they have been rapidly gaining popularity due to the possibility of handling many data, e.g. from mobile devices, IoT or Big Data.</p>



<h2 class="wp-block-heading">Relational vs non-relational database. The key difference</h2>



<p><strong>The structure</strong></p>



<ul class="wp-block-list">
<li>SQL databases store data in tables with a fixed number of rows and columns.</li>



<li>NoSQL databases store data using the below data models:</li>



<li>document databases (JSON documents)</li>



<li>Key-value data model (key – value pairs)</li>



<li>Graph databases</li>
</ul>



<p><strong>Scheme / Diagram</strong></p>



<ul class="wp-block-list">
<li><strong>SQL databases</strong> require a fixed, predefined schema. All data must have the same or similar structure. As a result, it is often necessary to have gathered the initial requirements for the system before starting work. In addition, the flexibility of the base may be compromised given that modifications (migrations) of the structure can be complicated and complex.</li>



<li><strong>NoSQL databases</strong> have a dynamic schema for unstructured data. A fixed schema definition is not required, which makes it easier to make changes to the structure.</li>
</ul>



<p><strong>Scalability</strong></p>



<ul class="wp-block-list">
<li><strong>SQL databases are vertically scalable (it is so-called scale-up)</strong>. This means that if you want to increase the amount of data stored on a single server, you need to increase RAM, CPU performance or SSD capacity. Scaling relational databases is rather more difficult. In order to maintain data integrity in transactions in a multi-server SQL database, a backend is needed that allows to synchronize all write operations and transactions in order to avoid the deadlock phenomenon (i.e. deadlock, mutual blocking of actions).</li>
</ul>



<ul class="wp-block-list">
<li><strong>NoSQL databases are characterized by horizontal scalability (scale-out)</strong>. This means that scaling is done by increasing the number of servers. JOIN operations allow you to combine and bind pieces of data. NoSQL databases typically are not designed to handle JOIN operations efficiently, but they do. Data can reside on different servers in NoSQL databases, where joining tables from multiple servers can be troublesome. NoSQL enables easy scaling by data sharding. Having a routing layer allows you to redirect the query to the appropriate shard, making NoSQL databases highly scalable and allowing for quick query handling.</li>
</ul>



<p><strong>Queries</strong></p>



<ul class="wp-block-list">
<li>The SQL language has been around for over 30 years, which is why it is widely used, popular and has a good reputation.<strong> It is extremely efficient when it comes to querying, operating, and retrieving data from relational databases.</strong> In addition, it is also distinguished by declarativeness (that is, it allows you to describe what is to be done with its help). The advantage of SQL is that it is quite easy to learn. This means that business analysts or other employees not related to programming can use it without major problems.</li>
</ul>



<ul class="wp-block-list">
<li>When it comes to NoSQL queries, it may not be as simple to use SQL in relational databases as it usually requires additional data processing and there is no single declarative query language. Therefore, tasks using NoSQL are usually performed by programmers.</li>
</ul>



<p>In summary, how to run queries in NoSQL databases largely depends on the database. For example, in MongoDB, to request data from a JSON document database, specify documents with properties that the results should match and use the following function: db.collection.find()<br><strong>Other popular solutions may include creating query functionality directly at the application layer (rather than at the database layer) or implementing MapReduce, a platform that facilitates the processing of big data.</strong></p>



<h2 class="wp-block-heading" id="Choosing-between-SQL-and-NoSQL">Choosing between SQL and NoSQL</h2>



<p>Now that we know the main differences between SQL and NoSQL, let’s try to answer the question: When to use relational databases and when to use non-relational databases? As is often the case in IT – the decision depends<br>on many components. In this case, the main points to consider are:</p>



<ul class="wp-block-list">
<li><strong>Data types</strong></li>



<li><strong>Database management method</strong></li>



<li><strong>Amount of data</strong></li>
</ul>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" width="756" height="310" src="https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.03.xx_graphic_1.png" alt="SQL vs NoSQL" class="wp-image-22240" title="NoSQL vs SQL databases. What&#039;s the difference? When to choose SQL database, and when NoSQL? 2" srcset="https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.03.xx_graphic_1.png 756w, https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.03.xx_graphic_1-300x123.png 300w, https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.03.xx_graphic_1-495x203.png 495w" sizes="(max-width: 756px) 100vw, 756px" /></figure></div>


<h3 class="wp-block-heading">When to use SQL?</h3>



<p>Referring to the first component, the type of data – in this case, <strong>relational databases will perform better than NoSQL databases, if data consistency and integrity are key.</strong><br>It is a common belief that relational databases are not a good choice for handling large amounts of data. This statement is not entirely true. <strong>Many databases like MySQL or PostgreSQL can handle large amounts of data very well.</strong> Relational databases have a fixed, fixed schema and require data that is structured. Maintaining such a structure, consistency and efficiency may turn out to be very difficult if, with the help of the relational base, we are going to handle the Big Data business.</p>



<p>At first glance, it might seem that the fixed data structures may be limiting, but there is no rule here. Having a fixed, predefined structure <strong>makes SQL databases a better option for handling payment systems or reservation systems.</strong> An interesting fact is that most financial institutions rely on relational databases. <strong>Relational databases ensure transactional </strong>nature, i.e. data integrity and correctness. SQL can limit some functionality at times, but on the other hand, it is a very mature and proven technology.</p>



<h3 class="wp-block-heading">When to use NoSQL?</h3>



<p>NoSQL databases can store different kinds of data and they don’t need to be structured in any way. <strong>Therefore, non-relational databases provide greater flexibility and are a good choice for handling large amounts of data without a common structure.</strong></p>



<p>Typically, the more extensive your data set is, the more likely a NoSQL database is to be the better choice. Non-relational databases are predisposed to scalability and availability, <strong>making them an ideal solution for real-time applications (e.g. online gambling, instant messaging).</strong></p>



<h3 class="wp-block-heading">How about using multiple databases?</h3>



<p>You first need to understand the domain. What effect are you trying to achieve? Nowadays, often the choice between SQL and NoSQL is not a question of which database to use, but of when and where to use each of these databases within the same application or system.</p>



<p>Personally, I am working on an application in which the use of NoSQL was – without going into details – the most sensible, but the same application also required reports. To avoid excessive problems and analyzes, I decided to use both types of databases. I used NoSQL<strong> for the web and desktop application and SQL for the reports themselves.</strong> The information is stored in the NoSQL database and only the data required for the reports is transferred to the SQL database.</p>



<h2 class="wp-block-heading" id="To-sum-up:-relational-database-or-non-relational-data-model?">To sum up: relational database or non-relational data model?</h2>



<p><strong>Choosing the right database is not easy, even for experts, and deciding whether to choose relational or non-relational databases can depend on many factors.</strong> You should also consider how many options are available in the market for SQL and NoSQL databases. For example, if you have a large amount of unstructured data, databases may be a good solution CouchDB or MongoDB. However, when high availability is your priority, they may be a better choice Redis and Cassandra.</p>



<p>On the other hand, SQL databases offer many advantages in terms of data transactions and their overall integrity. Moreover, the relationships within them are easily identified and defined, which makes it easier to draw conclusions from critical insights.</p>


</style><div class="promotion-box promotion-box--image-left promotion-box--full-width-without-image"><div class="tiles latest-news-once"><div class="tile"><div class="tile-content"><p class="promotion-box__description2"><strong>Consult your project directly with a specialist</strong></p>
<a class="btn btn-primary booking" href="https://outlook.office365.com/book/BookameetingwithMarek@gfi.fr/" target="_blank" rel="noopener">Book a meeting</a></div></div></div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://nearshore-it.eu/technologies/nosql-vs-sql-differences-and-use-cases/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MongoDB – the perfect database system for e-commerce?</title>
		<link>https://nearshore-it.eu/articles/mongodb-ecommerce-database/</link>
					<comments>https://nearshore-it.eu/articles/mongodb-ecommerce-database/#respond</comments>
		
		<dc:creator><![CDATA[Adam Sosinski]]></dc:creator>
		<pubDate>Wed, 12 Jan 2022 14:56:00 +0000</pubDate>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Technologies]]></category>
		<category><![CDATA[Ecommerce]]></category>
		<category><![CDATA[NoSQL]]></category>
		<guid isPermaLink="false">https://nearshore-it.eu/?p=22457</guid>

					<description><![CDATA[One of the key challenges for programmers, architects and managers involved in e-commerce projects is the selection of an appropriate database for storing data representing products or services. Just as products are physically kept in warehouses, in the virtual world information about them is stored in databases.]]></description>
										<content:encoded><![CDATA[
<p>When choosing a database management system (DBMS) for your online store, you need to pay attention to a number of different aspects: flexibility, high availability, reliability, handling multiple inquiries and data timeliness. An example of a popular system addressing these needs is MongoDB, the capabilities of which I will discuss in this article.</p>



<h2 class="wp-block-heading">E-commerce means more than online stores</h2>



<p>In simple terms,&nbsp;<a href="https://nearshore-it.eu/articles/technologies/top-e-commerce-trends-for-2021/" data-type="post" data-id="14123">e-commerce</a>&nbsp;means commercial transactions conducted electronically on the Internet. By this, we mean sale-purchase transactions, as payment and delivery can be done either online or offline. Online stores are the most popular type of this trade, and for some people they equate to the concept of e-commerce itself. It is worth noting, however, that apart from e-shops, we can also distinguish auction sites, e-exchange offices, electronic banking and betting platforms.</p>


</style><div class="promotion-box promotion-box--image-left "><div class="tiles latest-news-once"><div class="tile"><div class="tile-image"><img decoding="async" src="https://nearshore-it.eu/wp-content/uploads/2023/05/nearshore_2023.05.25_social.jpg" alt="nearshore 2023.05.25 social" title="MongoDB – the perfect database system for e-commerce? 3"></div><div class="tile-content"><p class="entry-title client-name">Nearshoring services</p>
Entrust your project to nearshore software development experts
<a class="btn btn-primary" href="https://nearshore-it.eu/it-nearshoring-services/" target="_blank" rel="noopener">Get started now!</a></div></div></div></div>



<h2 class="wp-block-heading">The challenges for your e-commerce database</h2>



<p>In the e-commerce industry, databases undertake special tasks.</p>



<p><strong>A well-configured database system should:</strong></p>



<ul class="wp-block-list">
<li>guarantee data availability 24/7,</li>



<li>maintain a high polling rate during periods of increased usage,</li>



<li>save large amounts of data,</li>



<li>provide information about changes (e.g. the availability of given products from the product catalog) dynamically and on an ongoing basis.</li>
</ul>



<p>This is especially important during peak sales periods, <strong>such as Black Friday or Cyber Monday, </strong>that can translate into an increased number of queries. For this reason, e-commerce companies should focus on database scalability.</p>



<h2 class="wp-block-heading">Which to choose: relational databases or non-relational databases?</h2>



<p>Let’s take a closer look at data storage for e-commerce services. We can choose from several&nbsp;databases, the best-known of which are <a href="https://nearshore-it.eu/articles/technologies/nosql-vs-sql-differences-and-use-cases/" data-type="post" data-id="22205">relational (SQL) and non-relational (NoSQL)</a>. Let’s take a look at the differences between them. To be more precise, SQL is a Structured Query Language, a language for retrieving data from a relational database. However, this type of database has been called an <strong>“SQL database”</strong>, so I will use this term for the purposes of comparison. It also makes it easier to remember the name of the second type – a NoSQL database – that is often referred to as <strong>“not SQL”.</strong></p>



<p>There are 5 basic differences between them:</p>



<figure class="wp-block-table is-style-stripes"><table><tbody><tr><td><strong>SQL</strong><br></td><td><strong>NoSQL</strong></td></tr><tr><td>clearly defined data relationships<br></td><td>no relationship; the data in our database is loosely coupled&nbsp;&nbsp;</td></tr><tr><td>data is stored in tables<br></td><td>data stored in documents, graphs, as the so-called key-value</td></tr><tr><td>defined schema<br></td><td>dynamic schema, unordered data</td></tr><tr><td>preferred in the case of multi-line operations<br></td><td>preferred when the speed of data acquisition is important</td></tr><tr><td>vertically scalable</td><td>horizontally scalable</td></tr></tbody></table></figure>



<p>As you can see, the NoSQL databases perfectly match the requirements and needs of the e-commerce market in terms of data availability and storage. Currently, the most popular database system of this type is MongoDB.</p>



<h2 class="wp-block-heading">What is MongoDB?</h2>



<p>MongoDB is a document database for easy creation and scaling. Documents are created and stored in&nbsp;<strong>BSON (Binary JSON)</strong>&nbsp;format. Thanks to the use of JSON, it’s very easy to convert the queries and results into a format that can “understand” the frontend code of the e-commerce application. It is also more understandable for humans. The NoSQL solution includes hierarchy, automatic fragmentation, and built-in replication for better scalability and high availability.</p>



<p>Now that we have a picture of what the main challenges are in e-commerce and are sure that MongoDB is a good choice for data storage, let’s learn more about&nbsp;<strong>how</strong>&nbsp;<strong>MongoDB can support the e-commerce industry.</strong></p>



<h2 class="wp-block-heading">Advantages of NoSQL databases in e-commerce – based on the example of MongoDB</h2>



<h3 class="wp-block-heading">Dynamic schemas</h3>



<p>Thanks to dynamic schemas, the documents in the collection do not have to have the same fields, and a given field can have different types depending on the document. This increases the flexibility of mapping to entities or objects. However, practice shows that the structure of documents inside the collection is similar. To guarantee this, MongoDB introduced the ability to set validation rules per collection.</p>



<h3 class="wp-block-heading">Easy hierarchization of data</h3>



<p>Thanks to the use of the JSON format, it’s easy to structure the data. You can do this by embedding one document in another or by providing references. The use of a given method should be considered individually for each collection. Embedding is recommended because it allows you to obtain data with a single query, which improves the system’s performance. References are worth considering for more complex hierarchy representations or when the benefits of embedding do not outweigh the effects of data duplication (such as the need to monitor changes when replacing data).</p>


</style><div class="promotion-box promotion-box--image-left "><div class="tiles latest-news-once"><div class="tile"><div class="tile-image"><img decoding="async" src="https://nearshore-it.eu/wp-content/uploads/2024/06/BigCTA_LeszekJaros.jpg" alt="BigCTA LeszekJaros" title="MongoDB – the perfect database system for e-commerce? 4"></div><div class="tile-content"><p class="entry-title client-name promotion-box__headline2">Streamline Your Application Maintenance</p>
<p class="promotion-box__description2"><strong>Leszek Jaros</strong>, our Head of Telco and AMS Practice, is here to help you navigate the complexities of Application Maintenance Services. Book a consultation to boost your application's efficiency</p>
<a class="btn btn-primary booking" href="https://outlook.office365.com/book/BookameetingwithLeszek@gfi.fr/" target="_blank" rel="noopener">Schedule a meeting</a></div></div></div></div>



<h3 class="wp-block-heading">Replication</h3>



<p>MongoDB utilizes a concept called&nbsp;<strong>Replica Set</strong>, which is a set of nodes containing the same data. This enables data replication, the purpose of which is to&nbsp;<strong>increase availability and protect against database server failures.</strong>&nbsp;A properly designed architecture also allows for faster access to data.</p>



<p>We will discuss the key assumptions and replication mechanisms on the basis of the diagram below.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="756" height="122" src="https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.02.16_graphic_1.png" alt="MongoDB ecommerce database" class="wp-image-22479" title="MongoDB – the perfect database system for e-commerce? 5" srcset="https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.02.16_graphic_1.png 756w, https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.02.16_graphic_1-300x48.png 300w, https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.02.16_graphic_1-495x80.png 495w" sizes="(max-width: 756px) 100vw, 756px" /></figure>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<p>The replica set consists of one node, the so-called Primary member, and Secondary members. There is also a special member of such a set, the&nbsp;<em>Arbiter</em>, which does not contain a copy of the data but is used to select an alternative in the event that the main server is unavailable.</p>



<p>Saving operations are performed only on the Primary instance, from which the built-in MongoDB mechanism then copies the data to the other instances.</p>



<p>By default, read operations also go through the Primary instance, but it’s possible to configure the nodes so that the secondary servers are used to handle queries, which may involve the occurrence of the so-called eventual-consistency, i.e. the delayed update of data.</p>



<p>The&nbsp;<strong>clocking mechanism (<em>heartbeat</em>)</strong>. Each of the nodes (<em>members</em>) polls the others every 2 seconds to check their availability. If the main server is unavailable, a new one is selected.</p>



<p><a href="https://docs.mongodb.com/manual/tutorial/deploy-replica-set/" target="_blank" rel="noreferrer noopener">Deploy a Replica Set — MongoDB Manual</a></p>



<p>This process consists in selecting the one with the highest priority from the remaining instances. According to documentation, the replica can have up to 50 nodes, of which only 7 can participate in the selection process (<em>voting</em>); the successor is chosen from among them. Other servers, named&nbsp;<em>Non-Voting</em>&nbsp;<em>members</em>, must have the properties&nbsp;<em>votes and priority</em>&nbsp;set to 0. Setting an uneven number of voting instances is recommended; hence, the minimum number of nodes in a replica set is 3.</p>



<h3 class="wp-block-heading">Fragmentation</h3>



<p>Fragmentation means the process of dividing a data set into smaller pieces. In doing so, you can scale your database horizontally, practically without any limits. For fragmentation, MongoDB uses a cluster that consists of:</p>



<ul class="wp-block-list">
<li><em><strong>Shard</strong></em> – the replica set that contains part of the collection (chunk),</li>



<li><strong><em>Router</em></strong> – it works a bit like a load balancer and, based on the configuration, forwards orders to the appropriate subcollection to balance the load,</li>



<li><strong><em>Config server</em> </strong>– which stores the metadata and a cluster configuration.</li>
</ul>



<p>The relationship between the components is presented in the following diagram:</p>



<figure class="wp-block-image size-full"><img decoding="async" width="756" height="260" src="https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.02.16_graphic_2.png" alt="MongoDB ecommerce" class="wp-image-22471" title="MongoDB – the perfect database system for e-commerce? 6" srcset="https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.02.16_graphic_2.png 756w, https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.02.16_graphic_2-300x103.png 300w, https://nearshore-it.eu/wp-content/uploads/2023/03/nearshore_2023.02.16_graphic_2-495x170.png 495w" sizes="(max-width: 756px) 100vw, 756px" /></figure>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<p>For fragmentation, it is important to choose the right key and strategy. When selecting the document field that you wish to use as the key, you need to consider:</p>



<ul class="wp-block-list">
<li><strong>Cardinality</strong> – how many elements we can divide the collection into in relation to the key,</li>



<li><strong>Repeatability</strong> – whether any value appears more often than the others,</li>



<li><strong>Consistency</strong> – whether the new key values are not increasing / decreasing linearly,</li>



<li><strong>Query frequency</strong> – the key should be used in the most frequent queries.</li>
</ul>



<p><strong>When it comes to strategies, there are two to take advantage of:</strong></p>



<h3 class="wp-block-heading">Hashed Sharding</h3>



<p>With this strategy, MongoDB automatically generates Hash from the key field values. It works well when the key values change consistently. Hash increases the consistent distribution of documents between shards. The disadvantage is that in the case of inquiries about a given scope, it is unlikely that all documents will be in one shard. This results in polling all parts of the collection (chunks), because the router cannot clearly determine which shard the searched documents are located in.</p>



<h3 class="wp-block-heading">Ranged Sharding</h3>



<p>Each of the shards holds parts of the collection within a given key-value range. This strategy works well when the set of values for the key is large, but each of them does not repeat often. The main advantage is that you can target your inquiry to a specific shard or collection, which significantly affects the polling speed. The built-in MongoDB mechanism serves divide into parts and to allocate them. The mechanism ensures that they are consistently distributed and tries to maintain similarity in their sizes. When deciding on fragmentation, remember that MongoDB does not have an option allowing you to merge data – you only run fragmentation again using a different key.</p>



<h3 class="wp-block-heading">Streams of change</h3>



<p>As of version 3.6, MongoDB allows you to listen for changes in a selected collection, database or the entire system, except for the admin, premises and config collections. This is done by starting the cursor, which allows you to iteratively navigate through events related to a given range. Since this mechanism uses aggregation, you can also listen for specific changes or modify received notifications. The basic requirement is to use a replica set as notification takes place at the point of saving changes in the majority of those that are responsible for data storage.</p>



<p>Change streams use a special, limited oplog collection to store information on operations that have an impact on the current state of the data. Documents in this collection rotate, which means that when the new document reaches the size limit of the collection, the oldest ones are deleted. Therefore, you should choose the appropriate size for this collection, depending on the frequency of events, so that you can capture the selected one before it is removed.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>According to predictions, the dynamic development of&nbsp;<strong>e-commerce in Poland will continue for the next few years.</strong>&nbsp;Customers’ requirements for websites or applications are growing. The most important factors in improving the&nbsp;<strong>Customer Experience</strong>&nbsp;<strong>include availability, speed and reliability.</strong>&nbsp;A properly configured database system such as MongoDB is resistant to failures, scalable, and allows you to hierarchize and store of large amounts of data, so it fulfils the needs of any e-commerce projects.</p>


</style><div class="promotion-box promotion-box--image-left promotion-box--full-width-without-image"><div class="tiles latest-news-once"><div class="tile"><div class="tile-content"><p class="promotion-box__description2"><strong>Consult your project directly with a specialist</strong></p>
<a class="btn btn-primary booking" href="https://outlook.office365.com/book/BookameetingwithLeszek@gfi.fr/" target="_blank" rel="noopener">Book a meeting</a></div></div></div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://nearshore-it.eu/articles/mongodb-ecommerce-database/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Neo4j – an invitation to graph databases</title>
		<link>https://nearshore-it.eu/articles/neo4j-invitation-to-graph-databases/</link>
					<comments>https://nearshore-it.eu/articles/neo4j-invitation-to-graph-databases/#respond</comments>
		
		<dc:creator><![CDATA[Marcin Jawor]]></dc:creator>
		<pubDate>Tue, 26 Nov 2019 09:01:00 +0000</pubDate>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Technologies]]></category>
		<category><![CDATA[NoSQL]]></category>
		<guid isPermaLink="false">https://nearshore-it.eu/?p=25108</guid>

					<description><![CDATA[How to choose the right database? Will graph databases work well in every project? Read the article and get to know the advantages of graph databases and explore representative of this genre, which is Neo4j.]]></description>
										<content:encoded><![CDATA[
<p>The popularity of graph databases is still growing. But how to choose the right database? And will graph databases work well in every project? In today’s article, I would like to take a look at the advantages of graph databases and encourage as many people as possible from the programming industry to take advantage of all the benefits they can bring to a developer’s daily work. I will pay special attention to my favorite representative of this genre, which is Neo4j.</p>



<div class="table-of-contents">
    <p class="title">Go To:</p>
    <ol>
                    <li><a href="#what-is-a-graph-database">1.  What is a graph database?</a></li>
                    <li><a href="#database-selection">2.  Database selection</a></li>
                    <li><a href="#advantages-of-neo4j">3.  Advantages of Neo4j</a></li>
                    <li><a href="#what-does-the-fact-that-neo4j-is-a-nosql-database-mean">4.  What does the fact that Neo4j is a NoSQL database mean?</a></li>
                    <li><a href="#bus-connection-search-engine-case-study">5.  Bus connection search engine – case study</a></li>
                    <li><a href="#the-troublesome-rdbms">6.  The troublesome RDBMS</a></li>
                    <li><a href="#rdbms-full-of-joins">7.  RDBMS full of Joins</a></li>
                    <li><a href="#rdbms-full-of-subqueries">8.  RDBMS full of subqueries</a></li>
                    <li><a href="#case-study-using-a-neo4j-graph">9.  Case study: Using a Neo4j graph</a></li>
                    <li><a href="#summary">10.  Summary</a></li>
            </ol>
</div>


<h2 class="wp-block-heading" id="what-is-a-graph-database">What is a graph database?</h2>



<p>Neo4j (<a href="https://neo4j.com/" target="_blank" rel="noopener">https://neo4j.com/</a>) is one of the most popular, if not the most popular, graph database. As&nbsp;a&nbsp;reminder, as well as to organize your knowledge:&nbsp;<strong>a graph is a composition of two types of&nbsp;elements, which are nodes and relationships</strong>. A node can represent a specific type or several types and has its own properties. Relationships, on the other hand, apart from a name and their own properties, have – most importantly – a direction of interaction. The properties mentioned above are collections of key&nbsp;–&nbsp;value pairs. They are used to store important information. For example: if the node is a person, then their properties can be: given name, last name, age or list of favorite books.</p>



<p>Relationships between nodes in Neo4j – as in graph databases in general – are just as important as the nodes in terms of data. We treat them as objects, the existence of which is determined by the presence of given nodes. The independent existence of relationships has no justification.</p>



<p>Relationships known from RDBMS (Relational Database Management System)-type databases are usually associated with marking data in a row of one table as reflected in a particular row of another table. This allows for cascading operations when editing or deleting data. When normalizing a data model in RDBMS, we can come across the necessity of introducing special intermediate tables between the two tables used for binding whole groups of rows together.</p>



<p><strong>Read also:&nbsp;<a href="https://www.jcommerce.eu/jpro/articles/clean-architecture-en" target="_blank" rel="noopener">Clean Architecture</a>&nbsp;</strong></p>



<h2 class="wp-block-heading" id="database-selection">Database selection</h2>



<p>Many communities may still cling to the belief that RDBMS are ideally suited to all kinds of tasks. Decision-makers responsible for database selection may have negative attitudes toward alternative data storage methods, and Neo4j has long been considered such an alternative.&nbsp;<strong>How can you reasonably choose the database(s) to use in a given project? First and foremost, the choice should be determined by the tasks facing your application.</strong></p>



<p>As early as at the stage of application design – at the very stage of database selection – it is worth considering several issues:</p>



<ul class="wp-block-list">
<li>What operations will be performed on the collected data in the future?</li>



<li>Will the application’s task be to save and read data without any of the more complicated operations?</li>



<li>Or maybe the most important issue will be mutual relationships between the data, and the program should help to analyze them?</li>
</ul>



<p>Therefore, database selection depends on the basic function of the application being designed, as well as on the nature of the data. Will it be the data of people employed in a particular organization, who co‑create its organizational structure, and will the application you are creating be used to ensure efficient document circulation between employees?&nbsp;<strong>Or maybe you have to develop a flight search engine? Or an application that will provide support for a transport company in terms of logistics? Or maybe you received a super-secret order from government special services to&nbsp;implement a system supporting the management of a network of agents and informants?</strong>&nbsp;I&nbsp;admit the last example is indeed slightly over the top, but this is mainly because the possibilities provided by graph databases are really enormous.</p>



<p>However, the principle of matching a database to the purpose of a given application is not always observed, and the supporters of new and often more appropriate solutions have to struggle with the skepticism of managers (“After all, no one uses these solutions”).</p>



<h2 class="wp-block-heading" id="advantages-of-neo4j">Advantages of Neo4j</h2>



<p>How surprised and astonished those critics must be when they see numerous logotypes of world-famous brands or government or research institutions when visiting the Neo4j project’s home page – from medical companies to scientific and research institutes to financial, transport, telecommunication and military companies. A full, extensive list and case studies are available&nbsp;<a href="https://neo4j.com/" target="_blank" rel="noopener">on the project website.</a>&nbsp;This is a tidbit for all data analysis and modeling professionals as well as application architects.</p>



<p>As you can see, the popularity of Neo4j and graph databases is still growing.&nbsp;<strong>In many rankings, including my own, the Neo4j database is one of the leaders of such solutions.</strong>&nbsp;It is worth mentioning that the creators of Neo4j took good care of friendly organization of clustering and cloud computing, and the most common solution is Neo4j hosted on AWS – which also speaks in its favor.</p>



<p>It is worth remembering that Neo4j – as a tool – is strongly supported by both modern code writing tools and popular frameworks, such as Spring Framework in the “<a href="https://spring.io/projects/spring-data-neo4j" target="_blank" rel="noopener">Spring Data Neo4j</a>” project. The fact that graph databases are being developed so intensively bodes well for the future.</p>



<h2 class="wp-block-heading" id="what-does-the-fact-that-neo4j-is-a-nosql-database-mean">What does the fact that Neo4j is a NoSQL database mean?</h2>



<p>Just as databases from the RDBMS group use SQL query language, Neo4j uses the Cypher language. In&nbsp;both cases they are declarative languages. While syntactically Cypher is similar to SQL in many aspects, one of the most frequently indicated differences is the use of the&nbsp;<strong>MATCH</strong>&nbsp;keyword instead of&nbsp;<strong>SELECT</strong>. Another one is the use – in literal terms – of relationship arrows.</p>



<p>Cypher is a very flexible language in terms of query building capabilities. This is well demonstrated in examples like this one, where we perform conditional matching. In SQL, we always place the condition in the&nbsp;<strong>WHERE</strong>&nbsp;clause, whereas in Cypher it can be included right at the stage of node declaration. We&nbsp;can create interesting and useful queries composed of stages, using the&nbsp;<strong>WITH</strong>&nbsp;clause.</p>



<p>Very important, and often even crucial, is the readability of queries, which we find here. Also noteworthy is the ease of writing queries for people who have an understanding of the graph and have encountered the spelling of queries in SQL before.</p>



<h2 class="wp-block-heading" id="bus-connection-search-engine-case-study">Bus connection search engine – case study</h2>



<p>The example of a ticket booking application presented below is a real-life example. The problem I faced came up a few years ago, mainly due to decision-makers’ attachment to solutions considered to be proven, and the development team’s reluctance to search for new possibilities.</p>



<p><strong>Project:</strong>&nbsp;bus ticket booking application.</p>



<p><strong>End product:</strong>&nbsp;seat booking and ticket purchase. Due to the excessive complexity of the topic, however, let’s limit ourselves to the connection search engine only.</p>



<p><strong>Operation of the application:</strong>&nbsp;before booking a ticket, the user should first indicate the bus stop from which they want to depart, as well as select the destination stop from the list of available stops.</p>



<p><strong>Modeling:</strong>&nbsp;in the case of a RDBMS-compliant approach, we will need at least three tables to model this area. The first one will be a register of bus stops and the second one will be a register of tracks on&nbsp;which the stops are located. In the third table, we will assign particular stops to particular tracks.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="544" src="https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_1.png" alt="Neo4j graph database" class="wp-image-34727" title="Neo4j – an invitation to graph databases 7" srcset="https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_1.png 1200w, https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_1-300x136.png 300w, https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_1-768x348.png 768w, https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_1-495x224.png 495w" sizes="auto, (max-width: 1200px) 100vw, 1200px" /></figure></div>


<p><em>Figure&nbsp;1. RDBMS-compliant table and relationship chart</em></p>



<h2 class="wp-block-heading" id="the-troublesome-rdbms">The troublesome RDBMS</h2>



<p>Here we can notice a typical problem with a table containing mapped relationships between individual rows of&nbsp;bound tables. The rows in the relationship contain cells filled with unreadable numbers usually belonging to the indexed table primary keys in the relationship. Deciphering the origin and meaning of&nbsp;these numbers can sometimes require considerable effort. The more complex the table, the more effort will be needed. In our example, such a bonding table could look like this:</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1201" height="914" src="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_2.png" alt="Neo4j table" class="wp-image-30144" title="Neo4j – an invitation to graph databases 8" srcset="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_2.png 1201w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_2-300x228.png 300w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_2-768x584.png 768w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_2-495x377.png 495w" sizes="auto, (max-width: 1201px) 100vw, 1201px" /></figure></div>


<p><em>Table&nbsp;1. Sample fragment of possible content of a ‘track_bus_stop’ table</em></p>



<p>We can find such “creations” in Many-to-Many relationships. They can be particularly burdensome when there are numerous tables, defined foreign keys and relationships in the project.&nbsp;<strong>They also prove problematic when there is a plethora of data in scripts, which is needed to supply test instances of databases for integration verification of the correctness of implementation.</strong>&nbsp;Such&nbsp;a&nbsp;situation is often crucial in terms of development. It is often necessary to work really hard to prepare new data records while maintaining the relationships with intermediate tables. The data contained in the rows must be unique or match the master data set, and it must be consistent with other “non-null” data from at least ten other tables. It may happen that recurring references start to appear in the data model, e.g.&nbsp;as a result of inattention. Then, without performing the operation of disabling all restrictions on the database, it is not possible to continue adding new data or even to import correct data into it.</p>



<h2 class="wp-block-heading" id="rdbms-full-of-joins">RDBMS full of Joins</h2>



<p>Let’s move on to the first step using the connection search engine. A passenger will search for all possible tracks assigned to a selected bus stop.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="107" src="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_3.png" alt="Neo4j schemat" class="wp-image-30147" title="Neo4j – an invitation to graph databases 9" srcset="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_3.png 1200w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_3-300x27.png 300w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_3-768x68.png 768w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_3-495x44.png 495w" sizes="auto, (max-width: 1200px) 100vw, 1200px" /></figure></div>


<p><em>Listing&nbsp;1. Query in SQL to search for the names of all tracks to which the sample “Pstrągowa” bus stop belongs</em></p>



<p>What interesting thing has just happened?&nbsp;<strong>At this stage, data from three separate tables has merged in the query into one and we can now choose the rows that contain the stop we&nbsp;are looking for.</strong>&nbsp;If one track is defined by an N of the stops that make it up and are connected to it by the names of the tracks, then we reject all the rows in which the assigned stop is different from the one we indicated.</p>



<p>Below is an example of a result table before stripping away the rows with a different bus stop name than the one given:</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1201" height="915" src="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_4.png" alt="28.10 graphic 4" class="wp-image-30150" title="Neo4j – an invitation to graph databases 10" srcset="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_4.png 1201w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_4-300x229.png 300w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_4-768x585.png 768w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_4-495x377.png 495w" sizes="auto, (max-width: 1201px) 100vw, 1201px" /></figure></div>


<p><em>Table&nbsp;2. Table showing a set of the most important data from the track and bus stop tables compiled together using the ‘track_bus_stop’ table</em></p>



<p>Having rejected the rows in which the bus stop name does not correspond to the one we indicated, we&nbsp;obtain the presented set of rows, which should then be appropriately trimmed by rejecting any repetitions.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1201" height="149" src="https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_5.png" alt="Neo4j grafika" class="wp-image-34734" title="Neo4j – an invitation to graph databases 11" srcset="https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_5.png 1201w, https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_5-300x37.png 300w, https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_5-768x95.png 768w, https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_5-495x61.png 495w" sizes="auto, (max-width: 1201px) 100vw, 1201px" /></figure>



<p><em>Table&nbsp;3. Set of unique track names to which the indicated bus stop belongs</em></p>



<h2 class="wp-block-heading" id="rdbms-full-of-subqueries">RDBMS full of subqueries</h2>



<p>Let’s imagine now that our passenger needs a list of all the bus stops which it is possible to reach by getting on the bus at the stop indicated. Below is a sample query that meets the expectations of the application user.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="320" src="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_6.png" alt="Neo4j listing" class="wp-image-30156" title="Neo4j – an invitation to graph databases 12" srcset="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_6.png 1200w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_6-300x80.png 300w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_6-768x205.png 768w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_6-495x132.png 495w" sizes="auto, (max-width: 1200px) 100vw, 1200px" /></figure></div>


<p><em>Listing&nbsp;2. Sample query returning a list of unique bus stops that can be reached from stop X</em></p>



<p>In the above query, we have to use two subqueries for one projection operation. There are a total of six table linking operations using the JOIN command.&nbsp;<strong>The complexity of this query is an undoubted disadvantage. Another disadvantage is the lack of intuitive character of SQL structures when we want to get a slice of the data set of the reality we are investigating.</strong>&nbsp;The result of the query in our example will be a set of data contained in the table below.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1201" height="192" src="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_7.png" alt="Neo4j tabela" class="wp-image-30159" title="Neo4j – an invitation to graph databases 13" srcset="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_7.png 1201w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_7-300x48.png 300w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_7-768x123.png 768w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_7-495x79.png 495w" sizes="auto, (max-width: 1201px) 100vw, 1201px" /></figure></div>


<p><em>Table&nbsp;4. Sample result set of possible bus stops to which the user will depart from the given initial stop</em></p>



<p>Queries from both previous listings are only an introduction to other operations leading to a ticket purchase. Further queries may sometimes be even more complex – especially once we create additional tables to store information about ticket prices depending on the chosen departure and destination stop, type of track, run, night-time or e.g. periodic discounts on given sections of the journey.</p>



<h2 class="wp-block-heading" id="case-study-using-a-neo4j-graph">Case study: Using a Neo4j graph</h2>



<p>Let’s take a look at the analyzed data model from the perspective of graph objects. What is the significance of the fact that something can be described using a graph? As I said at the beginning, a graph is a set of nodes and their mutual directed relationships. In the context of the analyzed bus connection search engine, our sample nodes and relationships can be presented in this way using Neo4j:</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="762" src="https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_8.png" alt="Neo4j image 2" class="wp-image-34738" title="Neo4j – an invitation to graph databases 14" srcset="https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_8.png 1200w, https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_8-300x191.png 300w, https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_8-768x488.png 768w, https://nearshore-it.eu/wp-content/uploads/2019/11/28.10_graphic_8-495x314.png 495w" sizes="auto, (max-width: 1200px) 100vw, 1200px" /></figure></div>


<p><em>Figure&nbsp;2. Graph showing the bus stops as nodes, along with their mutual defined relationships</em></p>



<p>The stops are nodes, and the road that leads from one stop to another naturally determines the relationship that exists between them. The road between the stops will result in the occurrence of&nbsp;appropriate tracks, so we will treat the track as a property of the relationship determined by the road.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1201" height="23" src="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_9.png" alt="Neo4j listing" class="wp-image-30165" style="object-fit:cover" title="Neo4j – an invitation to graph databases 15" srcset="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_9.png 1201w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_9-300x6.png 300w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_9-768x15.png 768w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_9-495x9.png 495w" sizes="auto, (max-width: 1201px) 100vw, 1201px" /></figure></div>


<p><em>Listing&nbsp;3. Query in Cypher that allows us to search for all tracks to which the indicated bus stop has been assigned</em></p>



<p>Sample result of the above query:</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1201" height="108" src="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_10.png" alt="neo4j table" class="wp-image-30168" title="Neo4j – an invitation to graph databases 16" srcset="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_10.png 1201w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_10-300x27.png 300w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_10-768x69.png 768w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_10-495x45.png 495w" sizes="auto, (max-width: 1201px) 100vw, 1201px" /></figure></div>


<p><em>Table&nbsp;5. Sample result of the query used to find all tracks to which the indicated bus stop belongs</em></p>



<p>At first glance, the Listing&nbsp;3 query is much more intuitive than the SQL one. It is certainly also less complicated. In the above query, we try to select all&nbsp;<strong>LEADS&nbsp;TO</strong>-type relationships to other bus stops – those coming out of the one whose name corresponds to the stop indicated in the query. We then return their tracks using the&nbsp;<strong>RETURN</strong>&nbsp;keyword.</p>



<p>Let’s go to step two, which should be done by the user in order to get a list of possible stops that the bus will drive through. In Neo4j, we will get this list by, for example, executing a query like the one presented in Listing&nbsp;4.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1201" height="45" src="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_11.png" alt="neo4j table" class="wp-image-30171" title="Neo4j – an invitation to graph databases 17" srcset="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_11.png 1201w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_11-300x11.png 300w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_11-768x29.png 768w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_11-495x19.png 495w" sizes="auto, (max-width: 1201px) 100vw, 1201px" /></figure></div>


<p><em>Listing&nbsp;4. The query will return the names of all the bus stops that can be reached from the one indicated by the user.</em></p>



<p>We can interpret the above query as follows:&nbsp;<strong>“Since there is a relationship between the indicated bus stop and the subsequent ones in the form of a road connecting them, then return all the subsequent stops to me until the last one.”</strong></p>



<p>Below is a sample result in the form of a graph and a table of names:</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="273" src="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_12.png" alt="Neo4j image" class="wp-image-30174" title="Neo4j – an invitation to graph databases 18" srcset="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_12.png 1200w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_12-300x68.png 300w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_12-768x175.png 768w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_12-495x113.png 495w" sizes="auto, (max-width: 1200px) 100vw, 1200px" /></figure></div>


<p><em>Figure&nbsp;3. Graph presenting possible destination stops and their mutual relationships</em></p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="1201" height="193" src="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_13.png" alt="Neo4j tabela" class="wp-image-30177" title="Neo4j – an invitation to graph databases 19" srcset="https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_13.png 1201w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_13-300x48.png 300w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_13-768x123.png 768w, https://nearshore-it.eu/wp-content/uploads/2024/09/28.10_graphic_13-495x80.png 495w" sizes="auto, (max-width: 1201px) 100vw, 1201px" /></figure></div>


<p><em>Table&nbsp;6. Set of node</em></p>



<p>As we can see in the above examples, queries in Cypher are much shorter than their equivalents in&nbsp;SQL, and presented in the relevant SQL listings. At the same time, they allow us to obtain identical effects. An additional advantage is that Neo4j, apart from the tabular view, offers also a view of nodes and their relationships.</p>



<h2 class="wp-block-heading" id="summary">Summary</h2>



<p>If the reality slice we are working on is a collection of objects and their mutual relationships, it is very likely that we will find a graph structure there, and therefore using a graph database will make sense. In&nbsp;this article, I wanted to present, above all, the intuitive character and ease of constructing queries in&nbsp;Neo4j. I provided an example of an application where I faced the problem of a mismatch between the tool and the project. If I had my current experience and knowledge of graph databases back then, I&nbsp;would have tried to convince the project’s decision-makers to use Neo4j. This would have protected the client from numerous unnecessary problems.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nearshore-it.eu/articles/neo4j-invitation-to-graph-databases/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
