<?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: Akbar Dizaji</title>
    <description>The latest articles on DEV Community by Akbar Dizaji (@akbar_dizaji).</description>
    <link>https://dev.to/akbar_dizaji</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%2F3034766%2Fe5bdc6a0-cf0f-4169-ab61-9a1b873a9b1d.png</url>
      <title>DEV Community: Akbar Dizaji</title>
      <link>https://dev.to/akbar_dizaji</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akbar_dizaji"/>
    <language>en</language>
    <item>
      <title>Why One Writer Can Beat Hundreds of Threads</title>
      <dc:creator>Akbar Dizaji</dc:creator>
      <pubDate>Mon, 03 Aug 2026 07:27:57 +0000</pubDate>
      <link>https://dev.to/akbar_dizaji/why-one-writer-can-beat-hundreds-of-threads-1gd4</link>
      <guid>https://dev.to/akbar_dizaji/why-one-writer-can-beat-hundreds-of-threads-1gd4</guid>
      <description>&lt;h1&gt;
  
  
  Single Writer Principle: Why Allowing Only a Single Writer to Do the Writing Can Speed Up Your Application
&lt;/h1&gt;

&lt;p&gt;Every day, you are using this approach without even knowing it.&lt;/p&gt;

&lt;p&gt;Forget about mutexes and fancy synchronization techniques for now. Let's ask ourselves a very basic question.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What if, instead of coordinating many writers writing in the same book, we allow just one writer to write there?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What would be its advantages? What would be its disadvantages?&lt;/p&gt;

&lt;p&gt;This basic concept forms the basis of many efficient and scalable applications that you will learn about later in the chapter. It is known as the &lt;strong&gt;Single Writer Principle&lt;/strong&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  In the Case of Race Between Several Authors
&lt;/h1&gt;

&lt;p&gt;Let’s picture an account that has &lt;strong&gt;100&lt;/strong&gt; dollars.&lt;/p&gt;

&lt;p&gt;Two commands almost simultaneously enter the system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;add 50&lt;/li&gt;
&lt;li&gt;subtract 20&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both threads would probably read &lt;strong&gt;100&lt;/strong&gt; as the initial amount, compute, and overwrite one another's calculation results.&lt;/p&gt;

&lt;p&gt;Depending on circumstances, the final balance may not be correct.&lt;/p&gt;

&lt;p&gt;Here we come across the typical &lt;strong&gt;race condition&lt;/strong&gt; problem.&lt;/p&gt;

&lt;p&gt;What is the very first solution that occurs?&lt;/p&gt;

&lt;p&gt;Indeed! – &lt;strong&gt;use a lock&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That works.&lt;/p&gt;

&lt;p&gt;But not for free, of course.&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%2Fprjpsjzzvxw9sr8nfwqk.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%2Fprjpsjzzvxw9sr8nfwqk.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  The Costs of Locking
&lt;/h1&gt;

&lt;p&gt;Many software developers believe that a lock is just a tiny cost - a few nanoseconds.&lt;/p&gt;

&lt;p&gt;In fact, the indirect costs may be significantly higher:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The threads wait for a lock.&lt;/li&gt;
&lt;li&gt;Context switching is done by the OS.&lt;/li&gt;
&lt;li&gt;CPU cores constantly invalidate cache lines of other cores (&lt;strong&gt;cache invalidation&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;Deadlocks can happen more often.&lt;/li&gt;
&lt;li&gt;The code gets really hard to understand and that's precisely what drives developers nuts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As the number of threads increases, performance does not necessarily increase.&lt;/p&gt;

&lt;p&gt;Quite often, it drops.&lt;/p&gt;

&lt;h1&gt;
  
  
  A More Sophisticated Approach - Keep Things Simple
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Allow Only One Thread to Write
&lt;/h2&gt;

&lt;p&gt;The Single Writer approach sounds pretty simple.&lt;/p&gt;

&lt;p&gt;Instead of letting every thread to update the shared state directly (&lt;strong&gt;note how important the term &lt;em&gt;state&lt;/em&gt; becomes here&lt;/strong&gt;) all threads just push their updates into the &lt;strong&gt;queue&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And a &lt;strong&gt;single thread&lt;/strong&gt; takes care of the queue processing requests one by one.&lt;/p&gt;

&lt;p&gt;No matter what, there is always just one writer that changes the shared state at the time.&lt;/p&gt;

&lt;p&gt;Since there is no concurrent writes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No race conditions anymore.&lt;/li&gt;
&lt;li&gt;Locks are usually redundant.&lt;/li&gt;
&lt;li&gt;The code becomes way more understandable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Why can a Single Thread be faster than Multiple Threads?
&lt;/h1&gt;

&lt;p&gt;At first glance, it sounds strange.&lt;/p&gt;

&lt;p&gt;How can a single thread be faster than multiple threads?&lt;/p&gt;

&lt;p&gt;But everything is very simple.&lt;/p&gt;

&lt;p&gt;If there is always a lock for which multiple threads are waiting, then all threads spend their time not working but competing among themselves for the right to take the lock.&lt;/p&gt;

&lt;p&gt;On the other hand, a Single Writer does not wait for locks and does not coordinate with other writers while processing incoming requests.&lt;/p&gt;

&lt;p&gt;CPU also gets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sequential access to memory&lt;/li&gt;
&lt;li&gt;Improved Cache Locality&lt;/li&gt;
&lt;li&gt;No Cache Line bouncing due to concurrent write operations&lt;/li&gt;
&lt;/ul&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%2Fm6rowaa5sh0q9b09zwra.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%2Fm6rowaa5sh0q9b09zwra.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's why, in a lot of highly performant systems, &lt;strong&gt;reduction of contention is more beneficial than increasing the number of threads.&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  When do you see this pattern?
&lt;/h1&gt;

&lt;p&gt;The Single Writer pattern is not only theoretical.&lt;/p&gt;

&lt;p&gt;There are many technologies that use this pattern.&lt;/p&gt;

&lt;h3&gt;
  
  
  LMAX Disruptor
&lt;/h3&gt;

&lt;p&gt;LMAX Disruptor is built in such a way that each piece of the state is written by exactly one writer, thus achieving the speed of millions operations per second.&lt;/p&gt;

&lt;h3&gt;
  
  
  Redis
&lt;/h3&gt;

&lt;p&gt;Probably the most familiar example.&lt;/p&gt;

&lt;p&gt;Redis executes commands through a single event loop.&lt;/p&gt;

&lt;p&gt;Because only one thread modifies its internal data structures, Redis doesn't need locks for most of its core operations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Actor Model (Akka, Orleans)
&lt;/h3&gt;

&lt;p&gt;Each actor owns its own state.&lt;/p&gt;

&lt;p&gt;Messages are processed sequentially, so only the actor itself can modify its internal state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Should You Always Use Single Writer?
&lt;/h2&gt;

&lt;p&gt;Of course not!&lt;/p&gt;

&lt;p&gt;In software engineering, rarely anything works all the time, except this statement itself :)&lt;/p&gt;

&lt;p&gt;If operations are fully independent and do not access shared state, running in parallel is preferable.&lt;/p&gt;

&lt;p&gt;But when multiple threads continuously compete to modify the shared state, the use of the Single Writer pattern can simplify the code and make it perform better.&lt;/p&gt;

&lt;p&gt;Note, that this pattern does not exclude the use of parallelism at all.&lt;/p&gt;

&lt;p&gt;Actually, the pattern &lt;strong&gt;shifts the point of parallelism to the place it makes sense.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Expensive calculations can still be performed in parallel.&lt;/p&gt;

&lt;p&gt;But the write to the shared state is done by only one thread.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;So, the Single Writer Principle can be formulated very briefly:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Each shared state should have only one writer.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This simple idea gets rid of most challenging aspects of concurrent programming.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No more race conditions.&lt;/li&gt;
&lt;li&gt;Locks become unnecessary.&lt;/li&gt;
&lt;li&gt;Code becomes easier to understand.&lt;/li&gt;
&lt;li&gt;Behavior becomes deterministic.&lt;/li&gt;
&lt;li&gt;Throughput is usually improved in cases of contention.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's why the high-performance system rarely starts with the addition of more threads.&lt;/p&gt;

&lt;p&gt;Instead, the following question is asked first:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Can we make the number of writers equal to one?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Page Splits in SQL Server AND Entity Framework</title>
      <dc:creator>Akbar Dizaji</dc:creator>
      <pubDate>Tue, 28 Jul 2026 05:15:32 +0000</pubDate>
      <link>https://dev.to/akbar_dizaji/page-splits-in-sql-server-and-entity-framework-ll</link>
      <guid>https://dev.to/akbar_dizaji/page-splits-in-sql-server-and-entity-framework-ll</guid>
      <description>&lt;h2&gt;
  
  
  How does SQL Server store data?
&lt;/h2&gt;

&lt;p&gt;Upon adding the row to SQL Server, it does not immediately write that row to the disk.&lt;br&gt;
It adds the data to the fixed-sized block called &lt;strong&gt;Page&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Think of the page as a piece of paper that exists in a notebook with a size of 8KB in SQL Server.&lt;/p&gt;

&lt;p&gt;After filling up one page, the remaining rows get added to another page.&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%2Fw4e96busobkro5b42evs.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%2Fw4e96busobkro5b42evs.png" alt=" " width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is an Index?
&lt;/h2&gt;

&lt;p&gt;Imagine you have a 500-page book and you want to find the chapter about a topic like .NET, you have two choices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start reading from page one until you find it.&lt;/li&gt;
&lt;li&gt;Use the table of contents.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The index can be termed as the table of content of the database.&lt;br&gt;
The only difference here is that SQL Server uses B+ Trees for indexes.&lt;/p&gt;

&lt;p&gt;Instead of looking at all the rows, SQL Server simply moves down the tree to find the data on the specific page.&lt;/p&gt;

&lt;p&gt;This makes the process much faster.&lt;/p&gt;

&lt;p&gt;And now the main question:&lt;/p&gt;
&lt;h2&gt;
  
  
  What is a Page Split?
&lt;/h2&gt;

&lt;p&gt;Suppose a page looks 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;Page 1

A
B
D
E
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you want to insert C.&lt;/p&gt;

&lt;p&gt;But the problem is that the page is already full and there isn't any space for the new row.&lt;/p&gt;

&lt;p&gt;SQL Server has to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Allocate a new page.&lt;/li&gt;
&lt;li&gt;Move roughly half of the existing rows to the new page.&lt;/li&gt;
&lt;li&gt;Insert C into its correct sorted position.&lt;/li&gt;
&lt;/ol&gt;

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

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

A
B
D
E
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

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

A               C
B               D
                E
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a &lt;strong&gt;Page Split&lt;/strong&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5q4n8sdwixi0pcwsvey1.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%2F5q4n8sdwixi0pcwsvey1.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why are Page Splits bad?
&lt;/h2&gt;

&lt;p&gt;At first glance, it seems like SQL Server only moved a few rows. But no. In reality, the operation is much more expensive.&lt;/p&gt;

&lt;p&gt;More disk writes: Instead of performing a simple INSERT, SQL Server must:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Allocate a new page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy rows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update the B+ Tree.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes each write operation more costly. And moving rows and updating the B+ Tree also takes extra CPU cycles. Furthermore, when splitting the page, SQL Server needs to briefly lock both the page and the B+ Tree structure. On heavily used databases, this causes extra contention and waits for other processes.&lt;/p&gt;

&lt;h2&gt;
  
  
  What causes Page Splits?
&lt;/h2&gt;

&lt;p&gt;The most common causes are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A clustered index built on random GUIDs (&lt;code&gt;NEWID()&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Updates that increase the size of existing rows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Completely full pages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An inappropriate Fill Factor.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How can you reduce Page Splits?
&lt;/h2&gt;

&lt;p&gt;*&lt;em&gt;- Use sequential keys:&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Instead of:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;NEWID()&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Prefer:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;IDENTITY&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;&lt;code&gt;NEWSEQUENTIALID()&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Since new rows are always inserted near the end of the index, page splits become much less frequent.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;- Configure Fill Factor&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
If you know a table receives frequent inserts or row-growth updates, you can intentionally leave free space inside every page.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;FILLFACTOR = 80&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
This tells SQL Server to fill each page to only 80%, leaving 20% free for future inserts.&lt;/p&gt;

&lt;p&gt;But we should remember, a very low Fill Factor isn't always better because it creates more pages, which can increase storage usage and slightly reduce read performance. The optimal value depends on your workload.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;- Rebuild indexes&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
If fragmentation becomes significant, rebuilding the index reorganizes the pages and removes fragmentation.&lt;/p&gt;
&lt;h2&gt;
  
  
  Fill Factor in Entity Framework Core
&lt;/h2&gt;

&lt;p&gt;EF Core provides built-in support for SQL Server's Fill Factor option.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;modelBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Entity&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;HasIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CreatedAt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;HasFillFactor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;80&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The generated migration produces SQL similar to:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE INDEX IX_Orders_CreatedAt&lt;br&gt;
ON Orders(CreatedAt)&lt;br&gt;
WITH (FILLFACTOR = 80);&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Page Split is a process in which a new row is added to a full page. In order to free up space for the newly added row, a new page is created, the rows are moved to the new page (about half), and the B+ tree structure is updated. The process ensures the maintenance of indexes in sorted form but adds to write overhead, CPU utilization, and fragmentation in heavy workloads. Sequential keys and proper setting of Fill Factor help prevent Page Splits.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Memory-Optimized Tables in SQL Server (Explained Simply)</title>
      <dc:creator>Akbar Dizaji</dc:creator>
      <pubDate>Sat, 18 Jul 2026 07:11:06 +0000</pubDate>
      <link>https://dev.to/akbar_dizaji/memory-optimized-tables-in-sql-server-explained-simply-1m58</link>
      <guid>https://dev.to/akbar_dizaji/memory-optimized-tables-in-sql-server-explained-simply-1m58</guid>
      <description>&lt;p&gt;Another unique thing about SQL Server is Memory-Optimized Tables. Many people think that the concept of Memory-Optimized Tables is just about storing the data in memory as opposed to storage, therefore making everything faster. Well, this is not completely  true.&lt;/p&gt;

&lt;h2&gt;
  
  
  What do ordinary tables look like?
&lt;/h2&gt;

&lt;p&gt;In an ordinary SQL Server table, data is stored persistently on storage. However, when the SQL Server is going to read or alter any piece of data, it has to load it into RAM (Buffer Pool) first. An INSERT or an UPDATE operation in SQL Server will typically involve alteration of data in memory and subsequent writing to storage.&lt;/p&gt;

&lt;p&gt;So even the ordinary tables take advantage of RAM heavily.&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%2Fu8h2pev4z3yppzsko7hf.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%2Fu8h2pev4z3yppzsko7hf.png" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What then is special about Memory-Optimized Tables?
&lt;/h2&gt;

&lt;p&gt;Well, it has more to do with how SQL Server handles the data rather than where it is actually stored.&lt;/p&gt;

&lt;p&gt;The conventional tables structure data into pages that are 8 KB. Each time any change is made to the data, SQL Server needs to handle the pages. In case there are several users accessing the same data at the same time, SQL Server uses features like Locks and Latches to keep everything under control.&lt;/p&gt;

&lt;p&gt;The Memory-Optimized Tables have a completely different internal structure altogether. They do not use pages for structuring data and eliminate most internal overheads. As such, they perform better in highly concurrent workloads.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Locks and Latches?
&lt;/h2&gt;

&lt;p&gt;Imagine you have a notebook.&lt;/p&gt;

&lt;p&gt;If two people try to edit the same page at the same time, one of them has to wait until the other finishes writing. That's similar to a Lock—it protects the data itself.&lt;/p&gt;

&lt;p&gt;Now imagine someone is turning the pages of the notebook. If another person tries to grab the same page while it's being moved, the notebook could be damaged. To prevent this, SQL Server briefly blocks access while it manipulates its internal structures. This is called a Latch. Unlike a Lock, a Latch protects SQL Server's internal memory structures rather than the user data.&lt;/p&gt;

&lt;p&gt;Memory-Optimized Tables eliminate much of this waiting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Versioning
&lt;/h2&gt;

&lt;p&gt;In the case of traditional tables, any changes are usually made directly to the row itself.&lt;/p&gt;

&lt;p&gt;However, with Memory-Optimized Tables, changes are not made to the existing row; rather, a new version of this row is generated by SQL Server. The previous version stays there as long as there are no transactions using it.&lt;/p&gt;

&lt;p&gt;This enables multiple users to read/write data at once without blocking one another.&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%2Fwne7c8c5zgu1nuvpp8rj.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%2Fwne7c8c5zgu1nuvpp8rj.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is MEMORY_OPTIMIZED_DATA?
&lt;/h2&gt;

&lt;p&gt;Great and important question. In case if your data is residing in memory, then what will happen if the server goes down?&lt;/p&gt;

&lt;p&gt;This is where the &lt;code&gt;MEMORY_OPTIMIZED_DATA&lt;/code&gt; filegroup plays an important role.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;MEMORY_OPTIMIZED_DATA&lt;/code&gt; filegroup in SQL Server is used to hold all the necessary details required for the recovery of durable Memory-Optimized tables after a restart. This will give persistence to your data.&lt;/p&gt;

&lt;p&gt;In other words, this filegroup is not a substitute for RAM, but rather the persistent place where SQL Server can retrieve the data after a restart.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is it not what the Index does as well?
&lt;/h2&gt;

&lt;p&gt;No.&lt;/p&gt;

&lt;p&gt;Indexing just increases the speed at which you locate the data.&lt;/p&gt;

&lt;p&gt;In case SQL Server requires locating a user record with the ID equal to 100, an Index will help locate it very quickly.&lt;/p&gt;

&lt;p&gt;But once located and when it should be updated, SQL Server will have to work with pages, locks, latches, and all other common methods.&lt;/p&gt;

&lt;p&gt;Memory-Optimized Tables enhance a totally different area of the system and its architecture for read/write processes.&lt;/p&gt;

&lt;p&gt;That is why in spite of good indexing, Memory-Optimized Tables give considerable performance boosts in systems handling thousands of simultaneous operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do all tables need to be Memory-Optimized?
&lt;/h2&gt;

&lt;p&gt;Absolutely not.&lt;/p&gt;

&lt;p&gt;In case when a table holds several thousand rows but is modified only a few hundreds times a day, there will be no advantages to using Memory-Optimized Tables.&lt;/p&gt;

&lt;p&gt;On the other hand, they are very useful for applications like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;User sessions storage&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Chat programs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Gaming websites&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Processing queues&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Large-scale financial applications that deal with a huge number of parallel transactions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When there are thousands of actions happening every second, Memory-Optimized Tables may be very beneficial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;The Memory-Optimized Tables do &lt;strong&gt;not&lt;/strong&gt; represent just another way to "store data in RAM". These are radically new storage structures that have been created with high-concurrency use-cases in mind. Memory-Optimized tables achieve their increased speed through optimization of internal structures and reduction of waiting time between concurrent actions through optimization of data handling in SQL Server's memory. The increased complexity of Memory-Optimized tables, however, makes them suitable for specific use-cases only.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
