<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oluwapelumi Odumosu</title>
    <description>The latest articles on DEV Community by Oluwapelumi Odumosu (@yukimyona).</description>
    <link>https://dev.to/yukimyona</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F435312%2Fd3d78194-e174-4cb9-b24a-0c6a0d8edbef.jpg</url>
      <title>DEV Community: Oluwapelumi Odumosu</title>
      <link>https://dev.to/yukimyona</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yukimyona"/>
    <language>en</language>
    <item>
      <title>A difficult backend problem I had to solve</title>
      <dc:creator>Oluwapelumi Odumosu</dc:creator>
      <pubDate>Fri, 28 Jun 2024 07:43:11 +0000</pubDate>
      <link>https://dev.to/yukimyona/a-difficult-backend-problem-i-had-to-solve-4d27</link>
      <guid>https://dev.to/yukimyona/a-difficult-backend-problem-i-had-to-solve-4d27</guid>
      <description>&lt;p&gt;I am relatively new to backend development and followed along with a tutorial to build a dummy first app.&lt;br&gt;
Then I started to look for other projects to build solely by myself and I found one but soon enough...I ran into an issue.&lt;/p&gt;

&lt;p&gt;I was to create an endpoint that allows users create articles and also add tags to the article, the problem now was how do I manage the articles and tags making sure they are related without having the same tag duplicated multiple times.&lt;/p&gt;

&lt;p&gt;So I asked myself, what if a different user creates another article with the same tag(s), do I make the tags unique to each article (this didn't make a whole lot of sense). &lt;br&gt;
How do I make sure the tags are "general" so if a user is the first to create an article with that tag(s) then that's fine as I'll just add a new record, however if others create and add the same tag then I need to find a way to not create another record for the already existing tag and just associate it.&lt;/p&gt;

&lt;p&gt;I used MySQL with NodeJS, then I remembered the concept of JOIN tables which I learned during my SQL course and realized I could create separate tables for articles and tags, and then have a join table that has the id of the article and the id of the tag.&lt;br&gt;
That way in my join table if I add a new record to the article table with id 1, and new tags with id 1 and 2.&lt;br&gt;
Then on my article_tags table I'd create two records, so that I know which article belongs to which tag. That means I'll have something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Article 1 - Tag 1
Article 1 - Tag 2.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I had my queries check for existence of tags in the DB when creating new articles so that I don't overwrite an existing tag when a new user uses it, but if the tag doesn't exist, then I add a new record for it on the tags table, if not I just associate the existing tag with the new article created.&lt;/p&gt;

&lt;p&gt;I'm not quite sure if this is the most efficient, but it was how I solved the bottleneck.&lt;/p&gt;

&lt;p&gt;HNG Internship would serve as an important step in my career as a backend developer, to get to work in a team, learn best practices and contribute to meaningful projects.&lt;/p&gt;

&lt;p&gt;It's also a chance for me to solve real-world problems just like the one I encountered which I described above as these would help me hone my skills to become a better backend developer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hng.tech/internship"&gt;HNG Internship&lt;/a&gt;&lt;br&gt;
&lt;a href="https://hng.tech/hire"&gt;HNG Hire&lt;/a&gt;&lt;/p&gt;

</description>
      <category>hng</category>
      <category>backend</category>
      <category>sql</category>
      <category>node</category>
    </item>
  </channel>
</rss>
