<?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: HkSolDev</title>
    <description>The latest articles on DEV Community by HkSolDev (@hksoldev).</description>
    <link>https://dev.to/hksoldev</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1122021%2F741ded18-7f62-485a-af3c-d1e4b8c77e8b.png</url>
      <title>DEV Community: HkSolDev</title>
      <link>https://dev.to/hksoldev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hksoldev"/>
    <language>en</language>
    <item>
      <title>Why Backend Apps Use Database Connection Pooling</title>
      <dc:creator>HkSolDev</dc:creator>
      <pubDate>Tue, 14 Jul 2026 16:28:59 +0000</pubDate>
      <link>https://dev.to/hksoldev/why-backend-apps-use-database-connection-pooling-p90</link>
      <guid>https://dev.to/hksoldev/why-backend-apps-use-database-connection-pooling-p90</guid>
      <description>&lt;h2&gt;
  
  
  Why Backend Apps Use Database Connection Pooling?
&lt;/h2&gt;

&lt;p&gt;Why not backend apps do not make a fresh database connection for every request.&lt;/p&gt;

&lt;p&gt;At first I was thinking that when a request comes, the app can just query the database directly and get the result. But that is not how it works. Before the query even runs, the backend has to open a database connection, authenticate with the database, create a session, and use some database resources for that connection state&lt;/p&gt;

&lt;p&gt;That means a database connection is not free. It takes time and also uses memory and CPU on the database side.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a database connection is ?
&lt;/h2&gt;

&lt;p&gt;When the backend wants to do some operation in the database, it first needs a connection to the database.&lt;/p&gt;

&lt;p&gt;To make that connection, the backend uses database credentials, then the database authenticates the client, creates session state, and allocates resources needed for that connection. Only after that can the backend run the query.&lt;/p&gt;

&lt;p&gt;So a connection is not just “send SQL and get result.” There is setup work before the actual query starts.&lt;/p&gt;

&lt;h2&gt;
  
  
  What happens when a backend opens a fresh connection
&lt;/h2&gt;

&lt;p&gt;If the backend opens a fresh connection for a request, the flow is roughly like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User sends an HTTP request.&lt;/li&gt;
&lt;li&gt;The backend opens a database connection.&lt;/li&gt;
&lt;li&gt;The database authenticates that connection.&lt;/li&gt;
&lt;li&gt;The backend sends the SQL query.&lt;/li&gt;
&lt;li&gt;The database processes the query.&lt;/li&gt;
&lt;li&gt;The database returns the result.&lt;/li&gt;
&lt;li&gt;The backend closes the database connection.&lt;/li&gt;
&lt;li&gt;The backend sends the HTTP response.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. User clicks "Get Articles" button
2. HTTP request reaches your server           [0ms]
3. App creates database connection           [20ms]  ← Connection overhead
4. App authenticates with database           [10ms]  ← Authentication overhead
5. App sends SQL query                       [1ms]   ← Actual work
6. Database processes query                  [5ms]   ← Actual work
7. Database returns results                  [1ms]   ← Actual work
8. App closes database connection            [5ms]   ← Connection overhead
9. App sends HTTP response                   [1ms]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in this flow, the query is only one part of the total work. Connection setup and teardown also add overhead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why doing that on every request is expensive
&lt;/h2&gt;

&lt;p&gt;If we make the connection for reach request &lt;br&gt;
First we have to go with all the above process for each connection the backend repeats this full process for every request, the extra overhead adds latency again and again. Under higher traffic, that also puts more pressure on the database because too many connections consume extra resources.&lt;/p&gt;

&lt;p&gt;If one req take 2-8 mb of the space think about the 1000 of connection, Database might take 2-8Gb just for the connection overhead.|&lt;/p&gt;

&lt;p&gt;That is why opening a new connection for every request is usually a bad idea for real backend systems. The app spends time creating and closing connections instead of just reusing them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What connection pooling is
&lt;/h2&gt;

&lt;p&gt;A Connection pooling is a cache of Database connection already open and ready to reuse.&lt;/p&gt;

&lt;p&gt;Instead of creating a new connection for each request, the application borrows a free connection from the pool, uses it for the query, and then returns it back to the pool. This avoids paying the full connection setup cost every time.&lt;/p&gt;

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

&lt;p&gt;So the main benefit of pooling is lower connection overhead and better control over how many active database connections exist at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  How a request works with a pool
&lt;/h2&gt;

&lt;p&gt;With a connection pool, the app does not always need to start from zero.&lt;/p&gt;

&lt;p&gt;When a request comes in, the backend asks the pool for an available connection. If one is free, it uses that connection to run the query and then returns it to the pool after the work is done. Some pools create connections early, while others create them lazily and grow up to a configured limit.&lt;/p&gt;

&lt;p&gt;This saves time because the app is reusing existing connections instead of building a fresh one for every request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes and limits.
&lt;/h2&gt;

&lt;p&gt;Connection pooling is useful, but it also has limits.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pool make Too large
&lt;/h4&gt;

&lt;p&gt;If make more no of connection into the pool does not does not automatically make the app faster, instead we fallback to the same issue that we try to solve with the pool.&lt;/p&gt;

&lt;h4&gt;
  
  
  Connection Leaks:-
&lt;/h4&gt;

&lt;p&gt;A connection leak happens when the app taken connection form the pool but never returned, so the pool slowly run out of the connection.&lt;/p&gt;

&lt;h4&gt;
  
  
  No Timeout settings:-
&lt;/h4&gt;

&lt;p&gt;If all connections are busy and there is no proper timeout, requests may hang too long while waiting for a free connection.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pool too small:
&lt;/h4&gt;

&lt;p&gt;If the pool is too small, requests start waiting for a free connection. Then the app feels slow even if the database itself is working fine.&lt;/p&gt;

&lt;h4&gt;
  
  
  Ignoring slow queries:
&lt;/h4&gt;

&lt;p&gt;A bad query can hold a connection hostage and block others.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thought
&lt;/h2&gt;

&lt;p&gt;The main thing learned today is that connection pooling is not about making the database magically faster. It is about avoiding repeated connection setup cost and managing database connections in a smarter way.&lt;/p&gt;

&lt;p&gt;So if a backend is opening a fresh database connection for every request, pooling is one of the first things to look at.&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>backenddevelopment</category>
      <category>databaseperformance</category>
      <category>databaseconnectionpooling</category>
    </item>
    <item>
      <title>Understanding How AI Agents Work?</title>
      <dc:creator>HkSolDev</dc:creator>
      <pubDate>Sun, 12 Jul 2026 00:58:20 +0000</pubDate>
      <link>https://dev.to/hksoldev/understanding-how-ai-agents-work-18lj</link>
      <guid>https://dev.to/hksoldev/understanding-how-ai-agents-work-18lj</guid>
      <description>&lt;p&gt;What is an AI Agent?&lt;/p&gt;

&lt;p&gt;The AI agent is a tool that helps the user to get the answer/info directly what he is seeking.&lt;/p&gt;

&lt;p&gt;If we just talk in the context of coding only before the AI come coding is like a open book exam where writing code is like answering the question in the test and if you stuck you just open the book or go to internet and get the answer but even its a open book exam you must atleast have a basic idea where to look and the available answer is suit for you code you not its like you look for an Math query and you checking the chemistry answer.&lt;/p&gt;

&lt;p&gt;What change after AI is that we all get our own guider who directly gives us the answer and relevant links to where he gets the answer for reference.&lt;/p&gt;

&lt;p&gt;So we can say that AI Agent is a more of our personal guider which we can use in any way, anytime we want.&lt;/p&gt;

&lt;p&gt;Workflow of AI Agents:-&lt;/p&gt;

&lt;p&gt;So we see we can use the AI Agent at many places and more of a guider now, let’s see how the guider does things behind to help us.&lt;/p&gt;

&lt;p&gt;Lets go with the example of the Open Book Test, and we user Our Guider AI Agent to clear the test.&lt;/p&gt;

&lt;p&gt;So we Stuck in some questions and Now We need the help of our Guider to get the answer for the relevant question.&lt;/p&gt;

&lt;p&gt;So the first question was whether our Guider needed to look at the Whole Book?&lt;/p&gt;

&lt;p&gt;The answer is no as book may be very long and its just a example of book the data can be very long so machine/ AI Agent cant look whole data at once so there is limited size it can look at a time and that called Context Window and its depends on LLM some have big window and some has small&lt;/p&gt;

&lt;p&gt;So the question may come now that the data is always more than the context window, so how can we store and get the answer?&lt;/p&gt;

&lt;p&gt;The answer is we divided the book into small chunks, let’s say pages or more small (put 1000 words at a time together into the list), we do not need to always look through the whole data to get the answer&lt;/p&gt;

&lt;p&gt;After dividing the Big PDF into small chunks, we pass the relevant chunks into the context window, and LLM can do the process&lt;/p&gt;

&lt;p&gt;from langchain_community.document_loaders import PyPDFLoader&lt;br&gt;
from langchain_text_splitters import RecursiveCharacterTextSplitter&lt;/p&gt;

&lt;h1&gt;
  
  
  put the file path of the File //
&lt;/h1&gt;

&lt;p&gt;file_path = "./example.pdf" &lt;/p&gt;

&lt;h1&gt;
  
  
  load the file by using the PyPDFLoader //
&lt;/h1&gt;

&lt;p&gt;loader = PyPDFLoader(file_path=file_path)&lt;br&gt;
 docs = []&lt;/p&gt;

&lt;p&gt;print("LOADER", loader)&lt;br&gt;
// Loads the file&lt;br&gt;
docs_lazy = loader.lazy_load()&lt;/p&gt;

&lt;p&gt;for doc in docs_lazy:&lt;br&gt;
    docs.append(doc)&lt;/p&gt;

&lt;h1&gt;
  
  
  Here we do the Choose the Textsplitter which help us to do the chunking and we give what
&lt;/h1&gt;

&lt;h1&gt;
  
  
  is the size of our chunk and we overlap the chunk as the data not lost when the chunk end
&lt;/h1&gt;

&lt;p&gt;text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)&lt;/p&gt;

&lt;h1&gt;
  
  
  Now we the splitter we make and made chunk of the docs we have on the basis of text
&lt;/h1&gt;

&lt;p&gt;text = text_splitter.split_documents(documents=docs)&lt;/p&gt;

&lt;p&gt;Why require to do Embedding:-&lt;/p&gt;

&lt;p&gt;Now we do the chunking or divide the data into small parts, you think now just put it into the vector database and we're good to go. But that’s not true as it is like we just put the text into the database and if the query comes it’s not possible to get the relevant data from the database.&lt;/p&gt;

&lt;p&gt;Take an example like Translation from English to Your Language&lt;/p&gt;

&lt;p&gt;“The sun sets in the west”&lt;/p&gt;

&lt;p&gt;Can its make sense if you translate the things word by word and say it may be, but its rare, most of the time it’s not you have to find the relation and semantic meaning for the words and how they are related to translate it well.&lt;/p&gt;

&lt;p&gt;I don’t like, grammar, and i have a sensei who always corrects me.&lt;/p&gt;

&lt;p&gt;So like in translation, we put the word based on its relation we put the chunking data in a way that the same meaning of words are closer to each other in the vector db so its easy and get the relevant data easily for the query.&lt;/p&gt;

&lt;p&gt;Do not worry, this is all done by the LLM.&lt;/p&gt;

&lt;p&gt;So far, we take a big file —&amp;gt; Divide the file into small chunks —&amp;gt; Do the Embedding of the chunks and put in the Vector Db.&lt;/p&gt;

&lt;p&gt;from langchain_google_genai import GoogleGenerativeAIEmbeddings&lt;/p&gt;

&lt;h1&gt;
  
  
  use the QdrantVectore Store to store the vector embedding
&lt;/h1&gt;

&lt;p&gt;from langchain_qdrant import QdrantVectorStore &lt;/p&gt;

&lt;h1&gt;
  
  
  Here we select the GoogleAi Embedder to make the embedding of our docs
&lt;/h1&gt;

&lt;p&gt;embedder = GoogleGenerativeAIEmbeddings(&lt;br&gt;
    model="models/text-embedding-004",&lt;br&gt;
    google_api_key="Your Api key",&lt;br&gt;
)&lt;/p&gt;

&lt;h1&gt;
  
  
  Now we make a vectore store
&lt;/h1&gt;

&lt;p&gt;vector_store = QdrantVectorStore.from_documents(&lt;br&gt;
     documents=[],&lt;/p&gt;

&lt;h1&gt;
  
  
  The Url to which to connect
&lt;/h1&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; url="http://localhost:6333",
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  The collection name we have in our store in which we put all our embedding
&lt;/h1&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; collection_name="learning_langchain",
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  Give the embedder we make above
&lt;/h1&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; embedding=embedder,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;)&lt;/p&gt;

&lt;h1&gt;
  
  
  Now we have our store now lets put the doc in it we have and its make all the embedding and
&lt;/h1&gt;

&lt;h1&gt;
  
  
  All by itslef automatically
&lt;/h1&gt;

&lt;p&gt;vector_store.add_documents(documents=text)&lt;/p&gt;

&lt;p&gt;Retrieval &amp;amp; Generation -&lt;/p&gt;

&lt;p&gt;When the user asks a query/question, the agent:-&lt;/p&gt;

&lt;p&gt;When user asks a que/query, we can directly search the query in our database as user can ask anything, and its very hard and maybe the data we got is not fully correct to find what the user is asking about, so for this.&lt;/p&gt;

&lt;p&gt;We convert the user query into an embedding.&lt;/p&gt;

&lt;p&gt;Then we get the embedding of the query and search into our Vector Database for the relevant meaning word or similar semantic meaning.&lt;/p&gt;

&lt;p&gt;After getting the relevant semantic meaning, we pass the ( relevant data + user query ) to our LLM and we got the result.&lt;/p&gt;

&lt;p&gt;from langchain_qdrant import QdrantVectorStore&lt;/p&gt;

&lt;h1&gt;
  
  
  This we make to get the revelant data from our store
&lt;/h1&gt;

&lt;p&gt;retriver = QdrantVectorStore.from_existing_collection(&lt;br&gt;
    url="&lt;a href="http://localhost:6333" rel="noopener noreferrer"&gt;http://localhost:6333&lt;/a&gt;",&lt;br&gt;
    collection_name="learning_langchain",&lt;br&gt;
    embedding=embedder,&lt;br&gt;
)&lt;/p&gt;

&lt;h1&gt;
  
  
  Query give By the user
&lt;/h1&gt;

&lt;p&gt;query = input("Ask the Doubt:=&amp;gt; ")&lt;/p&gt;

&lt;h1&gt;
  
  
  We put the query into our message array
&lt;/h1&gt;

&lt;p&gt;message.append({"role": "user", "content": query})&lt;/p&gt;

&lt;h1&gt;
  
  
  This will Find the revelant data on the basis of out query form the Database
&lt;/h1&gt;

&lt;p&gt;search_result = retriver.similarity_search(query)&lt;/p&gt;

&lt;h1&gt;
  
  
  Here we put the data we got from the retriver and put in message so our LLM have revelant data
&lt;/h1&gt;

&lt;h1&gt;
  
  
  and query to give us a better answer
&lt;/h1&gt;

&lt;p&gt;message.append({"role": "system", "content": search_result[0].page_content})&lt;/p&gt;

&lt;h1&gt;
  
  
  Now just give the message to our LLM
&lt;/h1&gt;

&lt;p&gt;res = client.chat.completions.create(&lt;br&gt;
    model="gemini-2.0-flash",&lt;br&gt;
    messages=message,&lt;br&gt;
    response_format={"type": "json_object"},&lt;br&gt;
)&lt;/p&gt;

&lt;h1&gt;
  
  
  Here We see the query Result from Our LLM
&lt;/h1&gt;

&lt;p&gt;print(res.choices[0].message.content)&lt;/p&gt;

&lt;p&gt;Connect With me:-&lt;/p&gt;

&lt;p&gt;Github:- &lt;a href="https://github.com/hksoldev" rel="noopener noreferrer"&gt;https://github.com/hksoldev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LinkedIn :- &lt;a href="https://www.linkedin.com/in/mrhemantkumarr/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/mrhemantkumarr/&lt;/a&gt; Youtube&lt;/p&gt;

&lt;p&gt;X(Twitter) :- &lt;a href="https://x.com/hksoldev" rel="noopener noreferrer"&gt;https://x.com/hksoldev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Discord:- &lt;a href="https://discordapp.com/users/1442491832591319182" rel="noopener noreferrer"&gt;https://discordapp.com/users/1442491832591319182&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Want to learn about Devops can anyone suggest where should start learn for free ?</title>
      <dc:creator>HkSolDev</dc:creator>
      <pubDate>Thu, 23 Jan 2025 15:48:06 +0000</pubDate>
      <link>https://dev.to/hksoldev/want-to-learn-about-devops-can-anyone-suggest-where-should-start-learn-for-free--1op0</link>
      <guid>https://dev.to/hksoldev/want-to-learn-about-devops-can-anyone-suggest-where-should-start-learn-for-free--1op0</guid>
      <description></description>
      <category>devops</category>
      <category>learning</category>
      <category>career</category>
    </item>
    <item>
      <title>Want to prepare for an interview for react i am fresher i dont know where to prepare for an interview anyone please tell me</title>
      <dc:creator>HkSolDev</dc:creator>
      <pubDate>Tue, 18 Jul 2023 12:34:11 +0000</pubDate>
      <link>https://dev.to/hksoldev/want-to-prepare-for-an-interview-for-react-i-am-fresher-i-dont-know-where-to-prepare-for-an-interview-anyone-please-tell-me-1bci</link>
      <guid>https://dev.to/hksoldev/want-to-prepare-for-an-interview-for-react-i-am-fresher-i-dont-know-where-to-prepare-for-an-interview-anyone-please-tell-me-1bci</guid>
      <description></description>
    </item>
  </channel>
</rss>
