<?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: Tanishka V</title>
    <description>The latest articles on DEV Community by Tanishka V (@tanishka_v_b7e4add4c1c1a4).</description>
    <link>https://dev.to/tanishka_v_b7e4add4c1c1a4</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%2F3839219%2F5821913f-bef0-42a7-b38f-7b7f2bf6ee91.jpg</url>
      <title>DEV Community: Tanishka V</title>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tanishka_v_b7e4add4c1c1a4"/>
    <language>en</language>
    <item>
      <title>CA 26 - Consistency</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Wed, 25 Mar 2026 16:58:04 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-26-consistency-4jl</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-26-consistency-4jl</guid>
      <description>&lt;p&gt;Ensuring Data Consistency in a Digital Wallet System&lt;/p&gt;

&lt;p&gt;In this experiment, I focused on understanding how a database maintains &lt;strong&gt;data consistency&lt;/strong&gt;, especially in a financial system like a digital wallet (PhonePe/GPay type). The key goal was to ensure that invalid states — such as negative account balances — are never allowed.&lt;/p&gt;




&lt;h3&gt;
  
  
  Initial Setup
&lt;/h3&gt;

&lt;p&gt;I used the same &lt;code&gt;accounts&lt;/code&gt; table with a constraint to prevent negative balances:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```sql id="a1b2c3"&lt;br&gt;
CREATE TABLE accounts (&lt;br&gt;
    id SERIAL PRIMARY KEY,&lt;br&gt;
    name TEXT NOT NULL,&lt;br&gt;
    balance INT NOT NULL CHECK (balance &amp;gt;= 0),&lt;br&gt;
    last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;INSERT INTO accounts (name, balance)&lt;br&gt;
VALUES&lt;br&gt;
('Alice', 1000),&lt;br&gt;
('Bob', 500);&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


To verify:



```sql id="d4e5f6"
SELECT * FROM accounts;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Initial balances:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 1000&lt;/li&gt;
&lt;li&gt;Bob → 500&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Attempt 1: Deduct More Than Available Balance
&lt;/h3&gt;

&lt;p&gt;I tried to deduct more money than Alice has:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```sql id="g7h8i9"&lt;br&gt;
UPDATE accounts&lt;br&gt;
SET balance = balance - 1500&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

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


---

###  Observation

 PostgreSQL throws an error like:



```plaintext
ERROR: new row for relation "accounts" violates check constraint "accounts_balance_check"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Observation
&lt;/h3&gt;

&lt;p&gt;Again, PostgreSQL prevents the update with a constraint violation.&lt;/p&gt;

&lt;p&gt;✔ No invalid data is stored&lt;br&gt;
✔ Database enforces the rule strictly&lt;/p&gt;




&lt;h3&gt;
  
  
  Attempt 3: Inside a Transaction
&lt;/h3&gt;



&lt;p&gt;```sql id="m4n5o6"&lt;br&gt;
BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 2000&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;

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


---

###  Observation

 The transaction fails and is **automatically rolled back**

✔ No partial update
✔ Balance remains valid

---

###  Key Observations

* The database **does not allow negative balances**
* All invalid operations are **blocked immediately**
* Errors occur due to **CHECK constraint**, not transaction logic

---

###  Understanding Consistency

This demonstrates the **Consistency** property of ACID:

* Database always moves from one valid state to another
* Invalid states (like negative balance) are never allowed
* Constraints ensure rules are enforced automatically

---

###  Schema-Level vs Application-Level Rules

####  Enforced by Database (Schema Level)

* `CHECK (balance &amp;gt;= 0)`
* Prevents negative balances
* Automatically enforced by PostgreSQL

####  Must be Handled by Application

* Preventing overdraft before transaction
* Validating user input
* Avoiding duplicate transactions
* Business rules like daily transfer limits

---

###  Conclusion

Through this experiment, I observed that PostgreSQL strictly enforces data integrity using constraints. Even when I attempted invalid operations, the database rejected them and maintained a consistent state.

This highlights the importance of combining **database-level constraints** with **application-level logic** to build reliable systems. In real-world financial applications, both layers work together to ensure that data remains accurate, secure, and consistent at all times.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>CA - 25 Atomicity</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Wed, 25 Mar 2026 16:54:07 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-25-atomicity-1886</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-25-atomicity-1886</guid>
      <description>&lt;p&gt;Verifying Atomicity in a Digital Wallet Transaction&lt;/p&gt;

&lt;p&gt;In this experiment, I focused on designing a secure money transfer system similar to PhonePe or GPay, where transactions must be reliable and consistent. The main objective was to verify the &lt;strong&gt;Atomicity&lt;/strong&gt; property of transactions — ensuring that either all operations in a transaction are completed successfully or none of them are applied.&lt;/p&gt;




&lt;p&gt;Initial Setup&lt;/p&gt;

&lt;p&gt;I created the &lt;code&gt;accounts&lt;/code&gt; table and inserted sample data:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```sql id="1k8v3n"&lt;br&gt;
CREATE TABLE accounts (&lt;br&gt;
    id SERIAL PRIMARY KEY,&lt;br&gt;
    name TEXT NOT NULL,&lt;br&gt;
    balance INT NOT NULL CHECK (balance &amp;gt;= 0),&lt;br&gt;
    last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;INSERT INTO accounts (name, balance)&lt;br&gt;
VALUES&lt;br&gt;
('Alice', 1000),&lt;br&gt;
('Bob', 500);&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


To check the initial state:



```sql id="n8k2xq"
SELECT * FROM accounts;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Initial balances:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 1000&lt;/li&gt;
&lt;li&gt;Bob → 500&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;Performing a Successful Transaction&lt;/p&gt;

&lt;p&gt;I first implemented a correct transfer of 200 from Alice to Bob.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```sql id="x4v9pj"&lt;br&gt;
BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 200&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance + 200&lt;br&gt;
WHERE name = 'Bob';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


After execution:



```sql id="l7c3zm"
SELECT * FROM accounts;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Updated balances:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 800&lt;/li&gt;
&lt;li&gt;Bob → 700&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This confirms that both operations (debit and credit) were successfully completed.&lt;/p&gt;



&lt;p&gt;Introducing an Error After Debit&lt;/p&gt;

&lt;p&gt;Next, I simulated a failure scenario by introducing an error after deducting money from Alice but before crediting Bob.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```sql id="d2r5qw"&lt;br&gt;
BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 300&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;-- Intentional error (wrong column name)&lt;br&gt;
UPDATE accounts&lt;br&gt;
SET bal = balance + 300&lt;br&gt;
WHERE name = 'Bob';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


 The second query fails because `bal` does not exist.

---

 Observing the Result

Now, I checked the account balances:



```sql id="f6t8yn"
SELECT * FROM accounts;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Alice’s balance &lt;strong&gt;remains unchanged&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Bob’s balance &lt;strong&gt;remains unchanged&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This shows that the entire transaction was &lt;strong&gt;rolled back automatically&lt;/strong&gt; due to the error.&lt;/p&gt;



&lt;p&gt;Explicit Rollback Example&lt;/p&gt;

&lt;p&gt;To further confirm atomicity, I tested manual rollback:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```sql id="q1m7zs"&lt;br&gt;
BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 400&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;ROLLBACK;&lt;/p&gt;

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


Checking again:



```sql id="h3v9pk"
SELECT * FROM accounts;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Key Observations&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Even though the debit operation was executed, it was &lt;strong&gt;not permanently saved&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The database prevented &lt;strong&gt;partial updates&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Both operations (debit and credit) are treated as a &lt;strong&gt;single unit&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Understanding Atomicity&lt;/p&gt;

&lt;p&gt;This experiment demonstrates the &lt;strong&gt;Atomicity&lt;/strong&gt; property of ACID:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A transaction is &lt;strong&gt;all or nothing&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;If any part fails → entire transaction is rolled back&lt;/li&gt;
&lt;li&gt;No intermediate or partial changes are stored&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Through this experiment, I verified that PostgreSQL ensures atomic transactions. Even when errors occur in the middle of a transaction, the system automatically prevents partial updates and restores the database to its previous consistent state.&lt;/p&gt;

&lt;p&gt;This reinforces the importance of using transactions in applications like digital wallets, where accuracy and reliability are critical. Ensuring atomicity guarantees that financial operations remain safe and consistent, even in the presence of unexpected failures.&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
    </item>
    <item>
      <title>CA 27 - Isolation</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Wed, 25 Mar 2026 16:50:59 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-27-isolation-3ek5</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-27-isolation-3ek5</guid>
      <description>&lt;p&gt;Simulating Concurrent Transactions and Understanding Isolation in a Digital Wallet System&lt;/p&gt;

&lt;p&gt;In this experiment, I extended my digital wallet simulation (similar to PhonePe or GPay) to understand how databases handle concurrent transactions. In real-world systems, multiple users may try to access or modify the same data at the same time. If not handled properly, this can lead to serious issues like incorrect balances, duplicate deductions, or inconsistent data.&lt;/p&gt;




&lt;p&gt;Initial Setup&lt;/p&gt;

&lt;p&gt;I used the same &lt;code&gt;accounts&lt;/code&gt; table and dummy data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;last_updated&lt;/span&gt; &lt;span class="nb"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="k"&gt;CURRENT_TIMESTAMP&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initial state:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 1000&lt;/li&gt;
&lt;li&gt;Bob → 500&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Simulating Concurrent Transactions&lt;/p&gt;

&lt;p&gt;To simulate concurrency, I opened &lt;strong&gt;two query windows (sessions)&lt;/strong&gt; in pgAdmin.&lt;/p&gt;




&lt;p&gt;Session 1 (Transaction Not Committed)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Alice’s balance becomes &lt;strong&gt;700 (inside Session 1)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;BUT changes are &lt;strong&gt;NOT committed yet&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Session 2 (Concurrent Transaction)&lt;/p&gt;

&lt;p&gt;Now, in another query window:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Session 2 still sees &lt;strong&gt;Alice = 1000&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It &lt;strong&gt;cannot see uncommitted changes&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Trying Another Deduction in Session 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This query will &lt;strong&gt;WAIT (lock)&lt;/strong&gt; until Session 1 finishes&lt;/li&gt;
&lt;li&gt;PostgreSQL prevents conflicting updates&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Commit Session 1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 700&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Session 2 Continues&lt;/p&gt;

&lt;p&gt;After Session 1 commits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Session 2 resumes execution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Final result:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 200&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Observations&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Session 2 &lt;strong&gt;could not see uncommitted data&lt;/strong&gt; → prevents &lt;strong&gt;Dirty Reads&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;PostgreSQL used &lt;strong&gt;locking&lt;/strong&gt; to avoid simultaneous updates&lt;/li&gt;
&lt;li&gt;No inconsistent or corrupted balance occurred&lt;/li&gt;
&lt;/ul&gt;




&lt;ol&gt;
&lt;li&gt;READ COMMITTED (Default)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;TRANSACTION&lt;/span&gt; &lt;span class="k"&gt;ISOLATION&lt;/span&gt; &lt;span class="k"&gt;LEVEL&lt;/span&gt; &lt;span class="k"&gt;READ&lt;/span&gt; &lt;span class="k"&gt;COMMITTED&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Cannot see uncommitted data&lt;/li&gt;
&lt;li&gt;Prevents dirty reads&lt;/li&gt;
&lt;li&gt;May allow non-repeatable reads&lt;/li&gt;
&lt;/ul&gt;




&lt;ol&gt;
&lt;li&gt;REPEATABLE READ
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;TRANSACTION&lt;/span&gt; &lt;span class="k"&gt;ISOLATION&lt;/span&gt; &lt;span class="k"&gt;LEVEL&lt;/span&gt; &lt;span class="k"&gt;REPEATABLE&lt;/span&gt; &lt;span class="k"&gt;READ&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✔ Data remains consistent within the transaction&lt;br&gt;
✔ Prevents non-repeatable reads&lt;br&gt;
✔ Stronger consistency than READ COMMITTED&lt;/p&gt;




&lt;ol&gt;
&lt;li&gt;SERIALIZABLE
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;TRANSACTION&lt;/span&gt; &lt;span class="k"&gt;ISOLATION&lt;/span&gt; &lt;span class="k"&gt;LEVEL&lt;/span&gt; &lt;span class="k"&gt;SERIALIZABLE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Highest level of isolation&lt;/li&gt;
&lt;li&gt;Transactions behave as if executed one by one&lt;/li&gt;
&lt;li&gt;Prevents all anomalies (dirty reads, non-repeatable reads, lost updates)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;This experiment clearly showed how PostgreSQL handles concurrent transactions safely. Even when multiple sessions try to update the same account at the same time, the system ensures consistency using isolation levels and locking mechanisms.&lt;/p&gt;

&lt;p&gt;Understanding isolation is crucial when building financial systems, because it ensures that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No duplicate or conflicting transactions occur&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>computerscience</category>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
    </item>
    <item>
      <title>CA - 29 Idempotency</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Wed, 25 Mar 2026 16:47:03 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-29-idempotency-4a00</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-29-idempotency-4a00</guid>
      <description>&lt;p&gt;Simulating Duplicate Transactions and Understanding Their Impact&lt;/p&gt;

&lt;p&gt;In this experiment, I simulated a real-world issue where the same transaction (money transfer) is executed multiple times. This can happen in real systems due to network retries, slow responses, or duplicate requests from users. The goal was to observe how the database behaves in such situations and whether it prevents duplicate processing.&lt;/p&gt;




&lt;p&gt;Initial Setup&lt;/p&gt;

&lt;p&gt;I used the same accounts table with two users: Alice and Bob.&lt;/p&gt;

&lt;p&gt;sql id="z7k1qp"&lt;br&gt;
SELECT * FROM accounts;&lt;/p&gt;

&lt;p&gt;Initial balances:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 1000&lt;/li&gt;
&lt;li&gt;Bob → 500&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;First Transaction (Valid Transfer)&lt;/p&gt;

&lt;p&gt;I performed a transfer of 200 from Alice to Bob.&lt;/p&gt;

&lt;p&gt;sql id="t7x2pa"&lt;br&gt;
BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 200&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance + 200&lt;br&gt;
WHERE name = 'Bob';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;

&lt;p&gt;After execution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 800&lt;/li&gt;
&lt;li&gt;Bob → 700&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Repeating the Same Transaction (Duplicate Execution)&lt;/p&gt;

&lt;p&gt;Now, I executed the &lt;strong&gt;exact same transaction again&lt;/strong&gt;, simulating a duplicate request.&lt;/p&gt;

&lt;p&gt;sql id="4z91dp"&lt;br&gt;
BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 200&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance + 200&lt;br&gt;
WHERE name = 'Bob';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;

&lt;p&gt;After running this again:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 600&lt;/li&gt;
&lt;li&gt;Bob → 900&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Executing Again (Multiple Duplicates)&lt;/p&gt;

&lt;p&gt;Running it one more time:&lt;/p&gt;

&lt;p&gt;sql id="j9m8vk"&lt;br&gt;
BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 200&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance + 200&lt;br&gt;
WHERE name = 'Bob';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;

&lt;p&gt;Final balances:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 400&lt;/li&gt;
&lt;li&gt;Bob → 1100&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Observation&lt;/p&gt;

&lt;p&gt;From this experiment, it is clear that the database &lt;strong&gt;does not prevent duplicate transaction execution&lt;/strong&gt;. Each time the same query is executed, it is treated as a new transaction, and the balances are updated again.&lt;/p&gt;

&lt;p&gt;This leads to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple deductions from the sender&lt;/li&gt;
&lt;li&gt;Multiple credits to the receiver&lt;/li&gt;
&lt;li&gt;Incorrect and inconsistent account balances&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is dangerous in real-world systems, especially in financial applications, where even a single duplicate transaction can cause serious issues like money loss or incorrect balances.&lt;/p&gt;




&lt;p&gt;Real-World Solution Approaches&lt;/p&gt;

&lt;p&gt;To prevent such problems, real-world systems implement additional safeguards:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Idempotency Keys&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each transaction is assigned a unique ID.&lt;br&gt;
If the same request is received again, the system checks the ID and ignores duplicates.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Transaction Logging&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Systems maintain logs of all processed transactions to avoid reprocessing.&lt;/p&gt;




&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Through this simulation, I understood that databases like PostgreSQL will execute every valid query they receive, without automatically checking for duplicates. This highlights the importance of designing systems that handle repeated requests carefully.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>database</category>
      <category>sql</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>CA 28 - Durability</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Wed, 25 Mar 2026 16:44:05 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-28-durability-2g0i</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-28-durability-2g0i</guid>
      <description>&lt;p&gt;Simulating a Digital Wallet System and Understanding Transaction Durability&lt;/p&gt;

&lt;p&gt;As part of my database learning, I worked on simulating a simple digital wallet system, similar to applications like PhonePe or GPay. The goal was to understand how transactions are handled in a database and how systems ensure that operations like money transfers remain consistent and reliable, even in case of failures.&lt;/p&gt;




&lt;p&gt;Creating the Accounts Table&lt;/p&gt;

&lt;p&gt;To begin with, I created an &lt;code&gt;accounts&lt;/code&gt; table to store user details such as ID, name, balance, and last updated timestamp. I also added a constraint to ensure that the balance never becomes negative.&lt;br&gt;
sql&lt;br&gt;
CREATE TABLE accounts (&lt;br&gt;
    id SERIAL PRIMARY KEY,&lt;br&gt;
    name TEXT NOT NULL,&lt;br&gt;
    balance INT NOT NULL CHECK (balance &amp;gt;= 0),&lt;br&gt;
    last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP&lt;br&gt;
);&lt;/p&gt;



&lt;p&gt;Inserting Sample Data&lt;/p&gt;

&lt;p&gt;Next, I inserted some dummy data to simulate users in the system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this stage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 1000&lt;/li&gt;
&lt;li&gt;Bob → 500&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Performing a Money Transfer&lt;/p&gt;

&lt;p&gt;To simulate a transaction, I transferred 200 from Alice to Bob. I used transaction control commands to ensure both operations happen together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Verifying the Transaction&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After execution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 800&lt;/li&gt;
&lt;li&gt;Bob → 700&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This confirms that the transaction was successfully committed.&lt;/p&gt;




&lt;p&gt;Simulating a System Restart&lt;/p&gt;

&lt;p&gt;To test durability, I simulated a system restart by disconnecting and reconnecting to the database (or restarting PostgreSQL).&lt;/p&gt;

&lt;p&gt;After reconnecting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The balances remained:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alice → 800&lt;/li&gt;
&lt;li&gt;Bob → 700&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This shows that the committed transaction persists even after a restart.&lt;/p&gt;




&lt;p&gt;Understanding Durability&lt;/p&gt;

&lt;p&gt;This behavior demonstrates &lt;strong&gt;Durability&lt;/strong&gt;, one of the ACID properties. Once a transaction is committed, it is permanently stored in the database and cannot be lost, even in case of system failure.&lt;/p&gt;

&lt;p&gt;PostgreSQL ensures this using mechanisms like &lt;strong&gt;Write-Ahead Logging (WAL)&lt;/strong&gt;, where changes are first recorded in logs before being written to the actual database.&lt;/p&gt;




&lt;p&gt;Crash Before COMMIT&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Crash happens here (no COMMIT)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result: Changes are &lt;strong&gt;not saved&lt;/strong&gt;&lt;/p&gt;






&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Crash happens here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Testing Atomicity using ROLLBACK&lt;/p&gt;

&lt;p&gt;I also tested what happens when a transaction is cancelled.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;ROLLBACK&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alice’s balance remains unchanged.&lt;/p&gt;

&lt;p&gt;This demonstrates &lt;strong&gt;Atomicity&lt;/strong&gt;, meaning either all operations in a transaction are executed or none at all.&lt;/p&gt;




&lt;p&gt;Through this experiment, I understood how databases handle real-world financial operations securely. By using transactions (&lt;code&gt;BEGIN&lt;/code&gt;, &lt;code&gt;COMMIT&lt;/code&gt;, &lt;code&gt;ROLLBACK&lt;/code&gt;), I was able to ensure consistency and reliability in money transfers.&lt;/p&gt;

&lt;p&gt;This hands-on simulation helped me clearly understand ACID properties, especially &lt;strong&gt;Durability&lt;/strong&gt; and &lt;strong&gt;Atomicity&lt;/strong&gt;, and how they are essential in building systems like digital wallets where even a small inconsistency can lead to serious issues like incorrect balances or data loss.&lt;/p&gt;

</description>
      <category>database</category>
      <category>learning</category>
      <category>postgres</category>
      <category>sql</category>
    </item>
    <item>
      <title>SQL Fundamentals: Solving Real Database Queries Step by Step</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Tue, 24 Mar 2026 13:21:35 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/sql-fundamentals-solving-real-database-queries-step-by-step-11jh</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/sql-fundamentals-solving-real-database-queries-step-by-step-11jh</guid>
      <description>&lt;ul&gt;
&lt;li&gt;In this exercise, I worked on a variety of SQL queries using both the CITY and STATION (Weather Observation Station) tables. This helped me build a strong foundation in database querying and data analysis.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I began with basic queries such as retrieving all columns from the CITY table and gradually moved to more specific tasks like filtering cities based on country codes such as USA and JPN. I also learned how to extract only required fields like city names and apply conditions based on population.&lt;/p&gt;

&lt;p&gt;In addition to city-based queries, I explored weather-related datasets using the STATION table. ~ For example, I learned how to extract only American cities with populations greater than a certain threshold and how to retrieve only specific columns like city names.&lt;/p&gt;

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

&lt;p&gt;One interesting problem I solved involved retrieving a list of city names that do not start with vowels. To achieve this, I used multiple NOT LIKE conditions along with the DISTINCT keyword to ensure that duplicate entries were removed. This helped me better understand pattern matching and string filtering in SQL.&lt;/p&gt;

&lt;p&gt;~ One key concept I practiced was eliminating duplicate data using the DISTINCT keyword. For example, I solved a problem where I calculated the difference between the total number of city entries and the number of unique city names. This gave me insight into how duplicate data can affect analysis.&lt;/p&gt;

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

&lt;p&gt;Overall, this hands-on SQL practice enhanced my understanding of:&lt;/p&gt;

&lt;p&gt;~Data retrieval using SELECT&lt;br&gt;
~Filtering using WHERE conditions&lt;br&gt;
~Working with multiple datasets&lt;br&gt;
~Handling duplicates using DISTINCT&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>CA-22 : Select Queries from DVD Rental database</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Tue, 24 Mar 2026 09:07:40 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-22-select-queries-from-dvd-rental-database-1dpi</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/ca-22-select-queries-from-dvd-rental-database-1dpi</guid>
      <description>&lt;p&gt;Given task : Selecting queries from the dvd rental database using the postgre and pgadmin 4 on the macOS&lt;/p&gt;

&lt;p&gt;I started with basic data retrieval by selecting film titles along with their rental rates. To make the output more readable, I used column aliases to rename fields like title to Movie Title and rental_rate to Rate. This small step made a big difference in how clean the results looked.&lt;/p&gt;

&lt;p&gt;there were numerous task assigned to this specific topic which is 25 subtopics . &lt;br&gt;
^ Moving forward, I worked on sorting data. For example, I retrieved a list of films sorted by rental rate in descending order. In cases where multiple films had the same rental rate, I applied a secondary sort based on the title in alphabetical order. This introduced me to multi-level sorting using the ORDER BY clause.&lt;/p&gt;

&lt;p&gt;I also practiced sorting actor names by last name and then by first name, which reinforced my understanding of ordering data across multiple columns. Similarly, I retrieved unique values such as replacement costs, ratings, and rental durations using the DISTINCT keyword, which is very useful when dealing with repetitive data.&lt;/p&gt;

&lt;p&gt;Another interesting part was working with film details like title and duration. By renaming the length column to Duration (min), I made the output more intuitive. I also sorted films based on their length in descending order to identify longer movies.&lt;/p&gt;

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

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

&lt;p&gt;Additionally, I explored filtering and limiting data. For instance, I listed the 10 shortest films and retrieved the top 5 customers based on their customer IDs. These operations helped me understand how to control the size and relevance of query results.&lt;/p&gt;

&lt;p&gt;I also worked with store and inventory data by identifying unique store IDs and determining the first rental date for each store. This gave me more exposure to handling data across different tables.&lt;/p&gt;

&lt;p&gt;Finally, I practiced advanced sorting techniques, such as ordering films by multiple columns (like replacement cost and rental rate) and organizing customer and rental data in structured ways.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Overall, this exercise helped me strengthen my understanding of SQL concepts like:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Data retrieval using SELECT&lt;br&gt;
Column aliasing&lt;br&gt;
Sorting with ORDER BY&lt;br&gt;
Removing duplicates using DISTINCT&lt;br&gt;
Aggregation with functions like MIN()&lt;br&gt;
Grouping data using GROUP BY&lt;br&gt;
Limiting results with LIMIT&lt;/p&gt;

&lt;p&gt;This hands-on practice gave me a clearer idea of how SQL is used in real-world applications to manage and analyze structured data efficiently.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>ASSIGNMENT 20</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Mon, 23 Mar 2026 05:10:28 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/assignment-20-59do</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/assignment-20-59do</guid>
      <description>&lt;p&gt;Search in a Rotated Sorted Array (O(log n) Binary Search)&lt;/p&gt;

&lt;p&gt;Searching in a rotated array might look tricky at first — but with the right approach, it becomes elegant and efficient 🔥&lt;/p&gt;

&lt;p&gt;Let’s break it down 👇&lt;/p&gt;

&lt;p&gt;📌 Problem Statement&lt;/p&gt;

&lt;p&gt;You are given a sorted array that has been rotated at some unknown index.&lt;/p&gt;

&lt;p&gt;👉 Your task is to find the index of a target element.&lt;/p&gt;

&lt;p&gt;⚠️ Constraints:&lt;br&gt;
All elements are distinct&lt;br&gt;
Must run in O(log n) time&lt;br&gt;
If target not found → return -1&lt;br&gt;
🧪 Examples&lt;br&gt;
Example 1&lt;br&gt;
Input:  nums = [4,5,6,7,0,1,2], target = 0&lt;br&gt;
Output: 4&lt;br&gt;
Example 2&lt;br&gt;
Input:  nums = [4,5,6,7,0,1,2], target = 3&lt;br&gt;
Output: -1&lt;br&gt;
Example 3&lt;br&gt;
Input:  nums = [1], target = 0&lt;br&gt;
Output: -1&lt;br&gt;
💡 Key Insight&lt;/p&gt;

&lt;p&gt;Even though the array is rotated, one half is always sorted.&lt;/p&gt;

&lt;p&gt;👉 At any point:&lt;/p&gt;

&lt;p&gt;Either the left half is sorted&lt;br&gt;
Or the right half is sorted&lt;/p&gt;

&lt;p&gt;We use this property to apply Binary Search.&lt;/p&gt;

&lt;p&gt;🧠 Algorithm Strategy&lt;br&gt;
Find mid&lt;br&gt;
Check which half is sorted:&lt;br&gt;
If nums[low] &amp;lt;= nums[mid] → Left half is sorted&lt;br&gt;
Else → Right half is sorted&lt;br&gt;
Decide where target lies:&lt;br&gt;
If target is in sorted half → search there&lt;br&gt;
Else → search other half&lt;br&gt;
🔄 Step-by-Step Logic&lt;br&gt;
Case 1: Left Half is Sorted&lt;br&gt;
nums[low] &amp;lt;= nums[mid]&lt;/p&gt;

&lt;p&gt;If:&lt;/p&gt;

&lt;p&gt;nums[low] &amp;lt;= target &amp;lt; nums[mid]&lt;/p&gt;

&lt;p&gt;→ Search left&lt;/p&gt;

&lt;p&gt;Else → Search right&lt;br&gt;
Case 2: Right Half is Sorted&lt;br&gt;
nums[mid] &amp;lt; nums[high]&lt;/p&gt;

&lt;p&gt;If:&lt;/p&gt;

&lt;p&gt;nums[mid] &amp;lt; target &amp;lt;= nums[high]&lt;/p&gt;

&lt;p&gt;→ Search right&lt;/p&gt;

&lt;p&gt;Else → Search left&lt;br&gt;
💻 Python Implementation&lt;br&gt;
def search(nums, target):&lt;br&gt;
    low, high = 0, len(nums) - 1&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while low &amp;lt;= high:&lt;br&gt;
    mid = (low + high) // 2
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if nums[mid] == target:
    return mid

# Left half sorted
if nums[low] &amp;amp;lt;= nums[mid]:
    if nums[low] &amp;amp;lt;= target &amp;amp;lt; nums[mid]:
        high = mid - 1
    else:
        low = mid + 1

# Right half sorted
else:
    if nums[mid] &amp;amp;lt; target &amp;amp;lt;= nums[high]:
        low = mid + 1
    else:
        high = mid - 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;return -1&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Example usage&lt;br&gt;
&lt;/h1&gt;

&lt;p&gt;nums = [4,5,6,7,0,1,2]&lt;br&gt;
target = 0&lt;br&gt;
print(search(nums, target))&lt;br&gt;
🧾 Output&lt;br&gt;
4&lt;br&gt;
🔍 Dry Run (Quick Insight)&lt;/p&gt;

&lt;p&gt;For:&lt;/p&gt;

&lt;p&gt;[4,5,6,7,0,1,2], target = 0&lt;br&gt;
Mid = 7 → left sorted&lt;br&gt;
Target not in left → move right&lt;br&gt;
Eventually find 0 at index 4&lt;br&gt;
⚡ Complexity Analysis&lt;br&gt;
Metric  Value&lt;br&gt;
Time Complexity O(log n)&lt;br&gt;
Space Complexity    O(1)&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>computerscience</category>
      <category>dsa</category>
      <category>leetcode</category>
    </item>
    <item>
      <title>ASSIGNMENT 19</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Mon, 23 Mar 2026 05:09:09 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/assignment-19-1eid</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/assignment-19-1eid</guid>
      <description>&lt;p&gt;Find First and Last Occurrence in a Sorted Array (Binary Search)&lt;/p&gt;

&lt;p&gt;Searching efficiently in a sorted array is a must-know skill.&lt;br&gt;
Let’s solve a classic problem using Binary Search 👇&lt;/p&gt;

&lt;p&gt;📌 Problem Statement&lt;/p&gt;

&lt;p&gt;Given a sorted array arr&lt;a href="https://dev.tomay%20contain%20duplicates"&gt;&lt;/a&gt;, find the first and last occurrence of a given element x.&lt;/p&gt;

&lt;p&gt;⚠️ Conditions:&lt;br&gt;
If x is not found → return [-1, -1]&lt;br&gt;
Must be efficient (better than linear search)&lt;br&gt;
🧪 Examples&lt;br&gt;
Example 1&lt;br&gt;
Input:  arr = [1, 3, 5, 5, 5, 5, 67, 123, 125], x = 5&lt;br&gt;
Output: [2, 5]&lt;br&gt;
Example 2&lt;br&gt;
Input:  arr = [1, 3, 5, 5, 5, 5, 7, 123, 125], x = 7&lt;br&gt;
Output: [6, 6]&lt;br&gt;
💡 Optimal Approach: Modified Binary Search&lt;/p&gt;

&lt;p&gt;Instead of scanning the array, we use Binary Search twice:&lt;/p&gt;

&lt;p&gt;Find first occurrence&lt;br&gt;
Find last occurrence&lt;br&gt;
🧠 Key Idea&lt;br&gt;
For first occurrence:&lt;br&gt;
Move left even after finding x&lt;br&gt;
For last occurrence:&lt;br&gt;
Move right even after finding x&lt;br&gt;
🔄 Algorithm Steps&lt;br&gt;
🔍 First Occurrence&lt;br&gt;
If arr[mid] == x:&lt;br&gt;
Store index&lt;br&gt;
Move left (high = mid - 1)&lt;br&gt;
🔍 Last Occurrence&lt;br&gt;
If arr[mid] == x:&lt;br&gt;
Store index&lt;br&gt;
Move right (low = mid + 1)&lt;br&gt;
💻 Python Implementation&lt;br&gt;
def find_first(arr, x):&lt;br&gt;
    low, high = 0, len(arr) - 1&lt;br&gt;
    first = -1&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while low &amp;lt;= high:
    mid = (low + high) // 2

    if arr[mid] == x:
        first = mid
        high = mid - 1
    elif arr[mid] &amp;lt; x:
        low = mid + 1
    else:
        high = mid - 1

return first
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;def find_last(arr, x):&lt;br&gt;
    low, high = 0, len(arr) - 1&lt;br&gt;
    last = -1&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while low &amp;lt;= high:
    mid = (low + high) // 2

    if arr[mid] == x:
        last = mid
        low = mid + 1
    elif arr[mid] &amp;lt; x:
        low = mid + 1
    else:
        high = mid - 1

return last
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;def find_occurrences(arr, x):&lt;br&gt;
    return [find_first(arr, x), find_last(arr, x)]&lt;/p&gt;

&lt;h1&gt;
  
  
  Example usage
&lt;/h1&gt;

&lt;p&gt;arr = [1, 3, 5, 5, 5, 5, 67, 123, 125]&lt;br&gt;
x = 5&lt;br&gt;
print(find_occurrences(arr, x))&lt;br&gt;
🧾 Output&lt;br&gt;
[2, 5]&lt;br&gt;
🔍 Dry Run (Quick Insight)&lt;/p&gt;

&lt;p&gt;For:&lt;/p&gt;

&lt;p&gt;[1, 3, 5, 5, 5, 5, 67]&lt;br&gt;
First occurrence → keep moving left&lt;br&gt;
Last occurrence → keep moving right&lt;br&gt;
⚡ Complexity Analysis&lt;br&gt;
Metric  Value&lt;br&gt;
Time Complexity O(log n)&lt;br&gt;
Space Complexity    O(1)&lt;/p&gt;

&lt;p&gt;🏁 Conclusion&lt;/p&gt;

&lt;p&gt;This problem shows how powerful Binary Search can be when slightly modified.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>dsa</category>
      <category>interview</category>
      <category>leetcode</category>
    </item>
    <item>
      <title>ASSIGNMENT 18</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Mon, 23 Mar 2026 05:05:27 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/assignment-18-2cf</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/assignment-18-2cf</guid>
      <description>&lt;h2&gt;
  
  
  📌 Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given a sorted integer array &lt;code&gt;nums&lt;/code&gt; (in non-decreasing order), return a new array of the &lt;strong&gt;squares of each number&lt;/strong&gt;, also sorted in non-decreasing order.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Example 1
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input:  [-4, -1, 0, 3, 10]
Output: [0, 1, 9, 16, 100]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example 2
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input:  [-7, -3, 2, 3, 11]
Output: [4, 9, 9, 49, 121]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ❗ Why Not Just Square &amp;amp; Sort?
&lt;/h2&gt;

&lt;p&gt;A simple solution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;square → sort
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But that takes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⏱ &lt;strong&gt;O(n log n)&lt;/strong&gt; time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 We can do better: &lt;strong&gt;O(n)&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 Optimal Approach: Two-Pointer Technique
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🧠 Key Insight
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The array is sorted, BUT contains &lt;strong&gt;negative numbers&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Squaring negatives makes them positive → order breaks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 The &lt;strong&gt;largest square&lt;/strong&gt; will always come from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Either the &lt;strong&gt;leftmost element&lt;/strong&gt; OR&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;rightmost element&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔄 Algorithm Steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Initialize:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="n"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
   &lt;span class="n"&gt;right&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create result array of size &lt;code&gt;n&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Fill from &lt;strong&gt;end to start&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Compare:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;abs(nums[left])&lt;/code&gt; vs &lt;code&gt;abs(nums[right])&lt;/code&gt;

&lt;ol&gt;
&lt;li&gt;Place the larger square at the end&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💻 Python Implementation
&lt;/h2&gt;



&lt;p&gt;```python id="code1"&lt;br&gt;
def sorted_squares(nums):&lt;br&gt;
    n = len(nums)&lt;br&gt;
    result = [0] * n&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;left = 0
right = n - 1
pos = n - 1

while left &amp;lt;= right:
    if abs(nums[left]) &amp;gt; abs(nums[right]):
        result[pos] = nums[left] ** 2
        left += 1
    else:
        result[pos] = nums[right] ** 2
        right -= 1
    pos -= 1

return result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
  
  
  Example usage
&lt;/h1&gt;

&lt;p&gt;nums = [-4, -1, 0, 3, 10]&lt;br&gt;
print(sorted_squares(nums))&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


---

## 🧾 Output



```id="out1"
[0, 1, 9, 16, 100]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🔍 Dry Run (Quick Insight)
&lt;/h2&gt;

&lt;p&gt;For:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[-4, -1, 0, 3, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Compare &lt;code&gt;|-4|&lt;/code&gt; and &lt;code&gt;|10|&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Place &lt;code&gt;100&lt;/code&gt; at end&lt;/li&gt;
&lt;li&gt;Move inward and repeat&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚡ Complexity Analysis
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Time Complexity&lt;/td&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Complexity&lt;/td&gt;
&lt;td&gt;O(n)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🎯 Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Sorting after squaring is &lt;strong&gt;not optimal&lt;/strong&gt; ❌&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;two-pointer technique&lt;/strong&gt; for O(n) ✅&lt;/li&gt;
&lt;li&gt;Works because input array is already sorted 🔥&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🏁 Conclusion
&lt;/h2&gt;

&lt;p&gt;This problem is a great example of how &lt;strong&gt;understanding the data structure&lt;/strong&gt; can lead to optimized solutions.&lt;/p&gt;




</description>
    </item>
    <item>
      <title>ASSIGNMENT 13</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Mon, 23 Mar 2026 05:03:37 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/assignment-13-2c03</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/assignment-13-2c03</guid>
      <description>&lt;p&gt;Move All Zeros to the End (In-Place &amp;amp; Stable)&lt;/p&gt;

&lt;p&gt;Rearranging arrays efficiently is a key skill in coding interviews.&lt;br&gt;
Let’s solve a classic problem: moving all zeros to the end while maintaining order &lt;/p&gt;

&lt;p&gt;Problem Statement&lt;/p&gt;

&lt;p&gt;Given an integer array nums, move all 0s to the end of the array.&lt;/p&gt;

&lt;p&gt;Constraints:&lt;br&gt;
Maintain the relative order of non-zero elements&lt;br&gt;
Perform the operation in-place&lt;br&gt;
Do not create a copy of the array .&lt;/p&gt;

&lt;p&gt;Examples:&lt;br&gt;
Example 1&lt;br&gt;
Input:  [0, 1, 0, 3, 12]&lt;br&gt;
Output: [1, 3, 12, 0, 0]&lt;br&gt;
Example 2&lt;br&gt;
Input:  [0]&lt;br&gt;
Output: [0]&lt;br&gt;
 Optimal Approach: Two-Pointer Technique&lt;/p&gt;

&lt;p&gt;We use a two-pointer approach to solve this efficiently.&lt;/p&gt;

&lt;p&gt;i → scans the array&lt;br&gt;
j → tracks position to place next non-zero element&lt;/p&gt;

&lt;p&gt;-Move all non-zero elements forward&lt;br&gt;
-Fill remaining positions with 0s&lt;/p&gt;

&lt;p&gt;This ensures:&lt;/p&gt;

&lt;p&gt;Order is preserved .&lt;br&gt;
No extra space is used .&lt;/p&gt;

&lt;p&gt;~ Algorithm Steps ;&lt;/p&gt;

&lt;p&gt;Initialize j = 0&lt;br&gt;
Traverse array using i&lt;br&gt;
If nums[i] != 0:&lt;br&gt;
Swap nums[i] with nums[j]&lt;br&gt;
Increment j&lt;br&gt;
Continue till end&lt;/p&gt;

&lt;p&gt;Python Implementation&lt;br&gt;
def move_zeros(nums):&lt;br&gt;
    j = 0  # position for next non-zero&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in range(len(nums)):&lt;br&gt;
    if nums[i] != 0:&lt;br&gt;
        nums[i], nums[j] = nums[j], nums[i]&lt;br&gt;
        j += 1&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Example usage&lt;br&gt;
&lt;/h1&gt;

&lt;p&gt;nums = [0, 1, 0, 3, 12]&lt;br&gt;
move_zeros(nums)&lt;br&gt;
print(nums)&lt;/p&gt;

&lt;p&gt;~  Key Takeaways :&lt;br&gt;
Uses two-pointer technique &lt;br&gt;
Maintains relative order (stable) &lt;br&gt;
Works in-place &lt;br&gt;
Very common interview problem &lt;/p&gt;

</description>
    </item>
    <item>
      <title>ASSIGNMENT 12</title>
      <dc:creator>Tanishka V</dc:creator>
      <pubDate>Mon, 23 Mar 2026 05:00:21 +0000</pubDate>
      <link>https://dev.to/tanishka_v_b7e4add4c1c1a4/assignment-12-433e</link>
      <guid>https://dev.to/tanishka_v_b7e4add4c1c1a4/assignment-12-433e</guid>
      <description>&lt;p&gt;Next Permutation (In-Place &amp;amp; Optimal Solution)&lt;/p&gt;

&lt;p&gt;Understanding permutations is key in many algorithmic problems.&lt;br&gt;
Let’s solve a classic one: finding the next lexicographically greater permutation &lt;/p&gt;

&lt;p&gt;Given an array of integers nums, rearrange it into the next lexicographically greater permutation.&lt;/p&gt;

&lt;p&gt;Constraints:&lt;br&gt;
-Must be done in-place&lt;br&gt;
-Use only constant extra memory&lt;br&gt;
-If no greater permutation exists → return the lowest possible order (sorted ascending)&lt;/p&gt;

&lt;p&gt;Example 1&lt;br&gt;
Input:  [1, 2, 3]&lt;br&gt;
Output: [1, 3, 2]&lt;br&gt;
Example 2&lt;br&gt;
Input:  [3, 2, 1]&lt;br&gt;
Output: [1, 2, 3]&lt;br&gt;
Example 3&lt;br&gt;
Input:  [1, 1, 5]&lt;br&gt;
Output: [1, 5, 1]&lt;/p&gt;

&lt;p&gt;We want the next bigger arrangement, but just slightly bigger — not the maximum.&lt;/p&gt;

&lt;p&gt;Find a place where the order breaks&lt;br&gt;
Swap intelligently&lt;br&gt;
Rearrange the remaining part &lt;/p&gt;

&lt;p&gt;Step-by-Step Algorithm&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 1: Find the Breakpoint&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Traverse from right and find the first index i such that:&lt;/p&gt;

&lt;p&gt;nums[i] &amp;lt; nums[i + 1]&lt;/p&gt;

&lt;p&gt;If No Breakpoint Found&lt;/p&gt;

&lt;p&gt;The array is in descending order (largest permutation)&lt;/p&gt;

&lt;p&gt;Simply reverse it:&lt;/p&gt;

&lt;p&gt;[3,2,1] → [1,2,3]&lt;br&gt;
Step 2: Find Next Greater Element&lt;/p&gt;

&lt;p&gt;From the right side, find an element nums[j] such that:&lt;/p&gt;

&lt;p&gt;nums[j] &amp;gt; nums[i]&lt;br&gt;
 Step 3: Swap&lt;/p&gt;

&lt;p&gt;Swap:&lt;/p&gt;

&lt;p&gt;nums[i] ↔ nums[j]&lt;br&gt;
Step 4: Reverse the Right Half&lt;/p&gt;

&lt;p&gt;Reverse elements from:&lt;/p&gt;

&lt;p&gt;i + 1 → end&lt;/p&gt;

&lt;p&gt;This ensures the smallest possible order after the swap&lt;/p&gt;

&lt;p&gt;Python Implementation&lt;br&gt;
def next_permutation(nums):&lt;br&gt;
    n = len(nums)&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Step 1: Find breakpoint&lt;br&gt;
i = n - 2&lt;br&gt;
while i &amp;gt;= 0 and nums[i] &amp;gt;= nums[i + 1]:&lt;br&gt;
    i -= 1
&lt;h1&gt;
  
  
  Step 2: If breakpoint exists
&lt;/h1&gt;

&lt;p&gt;if i &amp;gt;= 0:&lt;br&gt;
    j = n - 1&lt;br&gt;
    while nums[j] &amp;lt;= nums[i]:&lt;br&gt;
        j -= 1&lt;br&gt;
    nums[i], nums[j] = nums[j], nums[i]&lt;/p&gt;
&lt;h1&gt;
  
  
  Step 3: Reverse the suffix
&lt;/h1&gt;

&lt;p&gt;left, right = i + 1, n - 1&lt;br&gt;
while left &amp;lt; right:&lt;br&gt;
    nums[left], nums[right] = nums[right], nums[left]&lt;br&gt;
    left += 1&lt;br&gt;
    right -= 1&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Example usage&lt;br&gt;
&lt;/h1&gt;

&lt;p&gt;nums = [1, 2, 3]&lt;br&gt;
next_permutation(nums)&lt;br&gt;
print(nums)&lt;/p&gt;

</description>
      <category>programming</category>
    </item>
  </channel>
</rss>
