<?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: Mazen Aly Abdelfattah</title>
    <description>The latest articles on DEV Community by Mazen Aly Abdelfattah (@mazen-13).</description>
    <link>https://dev.to/mazen-13</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%2F3951938%2F197107da-8d37-4fb6-9f1a-5c8029f96024.png</url>
      <title>DEV Community: Mazen Aly Abdelfattah</title>
      <link>https://dev.to/mazen-13</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mazen-13"/>
    <language>en</language>
    <item>
      <title>Part 5: Enhancements and Architecture Decisions</title>
      <dc:creator>Mazen Aly Abdelfattah</dc:creator>
      <pubDate>Thu, 26 Nov 2026 11:53:00 +0000</pubDate>
      <link>https://dev.to/mazen-13/part-5-enhancements-and-architecture-decisions-26h7</link>
      <guid>https://dev.to/mazen-13/part-5-enhancements-and-architecture-decisions-26h7</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Finally, I have successfully finished this project, I learned a lot about different technologies and system design concepts and want to share the decisions and enhancements that I made and what I learned.&lt;/p&gt;




&lt;h2&gt;
  
  
  Enhancing Database Read Latency via Batch Fetching
&lt;/h2&gt;

&lt;p&gt;This is a way to avoid the &lt;strong&gt;N+1 query problem&lt;/strong&gt;, and also avoid the duplication for rows that have many related rows in the other table that happens in join.&lt;br&gt;
The batch-loading is simply fetching all of the related data in one query with the collected IDs.&lt;/p&gt;

&lt;p&gt;For example, we first fetch all board columns, then fetch their tasks in another query using &lt;code&gt;WHERE column_id IN (col_id_1, col_id_2, ...)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I decided to use it and it sends just 3 queries for the full board details including columns in each board and tasks in each column.&lt;/p&gt;


&lt;h2&gt;
  
  
  Offloading Database Reads and Reducing Latency via Caching
&lt;/h2&gt;

&lt;p&gt;I found out that different caching strategies don't automatically eliminate consistency issues under concurrent operations, especially under the default rule for concurrent systems: &lt;em&gt;Start order does not guarantee completion order.&lt;/em&gt; Race conditions can still cause stale data be written into cache.&lt;/p&gt;

&lt;p&gt;I decided to use the cache-aside strategy because of its simplicity: reads populate the cache on misses, while writes update the database and invalidate the affected cache entries.&lt;/p&gt;
&lt;h3&gt;
  
  
  Race Condition in Cache-Aside Technique
&lt;/h3&gt;

&lt;p&gt;Suppose &lt;code&gt;board:1&lt;/code&gt; isn't cached yet, and its title in the database is "Old".&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;User X opens the board. Because the cache is empty, request will query the database and get board name "Old", then writes to cache.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Before the retrieved value is cached (before user x's request is finished), user Y renames the board to "New" then commits the change to the database and deletes &lt;code&gt;board:1&lt;/code&gt; entry from Redis to invalidate the cache, but since the key doesn't exist, nothing happens.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;User X's slow read request finally finishes and writes the stale value "Old" into Redis.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Redis now holds "Old" and DB holds "New". Every later reader gets "Old". Nothing will fix it.&lt;/p&gt;

&lt;p&gt;This is where the TTL provides an important safety net. The stale value will eventually expire, causing a cache miss and forcing the next reader to fetch the current value from the database.&lt;/p&gt;

&lt;p&gt;Therefore, when this race condition occurs, the TTL bounds the maximum time the stale value can remain in the cache. It doesn't prevent the race condition, yet limits its impact.&lt;/p&gt;
&lt;h3&gt;
  
  
  Deciding What to Cache
&lt;/h3&gt;

&lt;p&gt;Any request to read board details happens in 2 steps, the first is querying to the user-board roles table to check that the user is a member for this board, and the second is retrieving the board data. This could be solved via caching,  I decided to cache boards data as it is 3 database queries the first for board and the second for its columns and the third for tasks per each column, so it would be faster when cached. Also I decided to keep 5-minute TTL for each board.&lt;/p&gt;

&lt;p&gt;Also it is a good idea to cache user roles on boards as it is required in every action on the board or its columns or its tasks. Caching the roles &lt;strong&gt;trades security for speed&lt;/strong&gt;: a failed delete or race condition (explained above) can leave a stale role, so a user keeps old privileges from the cache until the TTL expires.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But database server can use RAM for faster retrieval, why to use Redis?&lt;/strong&gt;&lt;br&gt;
Without caching in memory (RAM), the database server would rerun the work on every request (parse, plan, join and executes, then retrieve then the mapping of ORM to an object) even it will read it from RAM instead of hard disk.&lt;/p&gt;

&lt;p&gt;A Redis hit skips all of that, because it returns the finished JSON. So RAM utilizing in database server removes the disk cost but not the compute cost.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Load Testing Profile and Enhancement
&lt;/h3&gt;

&lt;p&gt;I started with a simple baseline test that sent requests with random board IDs. It was useful as a quick sanity check, but it had several flaws that I addressed in my second testing profile:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Saturated, closed-loop load (fixed):&lt;/strong&gt; Both sets ran at the server's ceiling, so latencies were mostly &lt;strong&gt;queueing time&lt;/strong&gt; on one worker rather than single-request cost. The 6.5x P95 gain mixed "faster per request" with "less queueing," overstating what a single user would feel. In the updated profile, I moved away from a saturated ceiling test to better isolate request behavior.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Easy, uniform workload (fixed):&lt;/strong&gt; The baseline was read-only with uniform access over 50 boards, giving a near-perfect hit ratio without testing invalidation or hot keys. In the new profile, I added a &lt;strong&gt;mixed read/write workload&lt;/strong&gt; (to exercise cache invalidation) and &lt;strong&gt;skewed board reads&lt;/strong&gt; so some boards get heavier traffic than others, mimicking real-world access patterns.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Runs shorter than the TTL (fixed):&lt;/strong&gt; At 20s per run against a 300s TTL, expirations and stampedes were rare, and the "after" set mixed cold and warm runs. In the updated profile, I adjusted the TTL and run duration so boards actually expire during the test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Weak correctness checks:&lt;/strong&gt; The only check was HTTP &lt;code&gt;200&lt;/code&gt;, meaning a stale cached board would still pass.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With mixed read/write traffic, skewed reads, and real expirations in place, the second profile gave me a much more realistic picture of caching and invalidation behavior.&lt;/p&gt;
&lt;h3&gt;
  
  
  Results of Caching
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Cache Hit:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;keyspace_hits: 2339&lt;/li&gt;
&lt;li&gt;keyspace_misses: 710&lt;/li&gt;
&lt;li&gt;cache-hit ratio: ~75%&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  P99 Latency Across All Runs
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Baseline Runs (Without Caching)&lt;br&gt;
Run 1: 558.53ms&lt;br&gt;
Run 2: 935.97ms&lt;br&gt;
Run 3: 647.41ms&lt;br&gt;
Average: 713.97ms&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cached Runs (With Caching)&lt;br&gt;
Run 1: 163.51ms&lt;br&gt;
Run 2: 112.28ms&lt;br&gt;
Run 3: 133.20ms&lt;br&gt;
Average: 136.33ms&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Absolute Reduction: Dropped by 577.64ms&lt;br&gt;
Percentage Improvement: 80.9% faster&lt;/p&gt;
&lt;h4&gt;
  
  
  Throughput
&lt;/h4&gt;

&lt;p&gt;The throughput (number of handled requests per second) did not change, as the test runs with a moderate load that the server could withstand and handle without being stressed. Caching here allowed the system to serve these requests 80% faster at P99 with significantly less DB strain rather than pushing higher req/s, if the load was high and the server is saturated , then there would be improvement in the throughput as the server can serve/process more requests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For detailed k6 load testing results, take a look on the GitHub Repo &lt;code&gt;tests&lt;/code&gt; folder:&lt;/strong&gt;&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/mazenaly256" rel="noopener noreferrer"&gt;
        mazenaly256
      &lt;/a&gt; / &lt;a href="https://github.com/mazenaly256/Kanban-Flow" rel="noopener noreferrer"&gt;
        Kanban-Flow
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Real-time collaborative project management web application with Kanban-style boards
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;





&lt;h2&gt;
  
  
  The Problem in Inline Side Effects
&lt;/h2&gt;

&lt;p&gt;I identified a problem that is the task write endpoint was orchestrating everything:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Commit to Postgres (the source of truth).&lt;/li&gt;
&lt;li&gt;Delete the Redis cache key.&lt;/li&gt;
&lt;li&gt;Broadcast over WS.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With this inline synchronous setup, the endpoint knows about every downstream system (tight coupling) and waits for each side effect to finish successfully before executing the next one. Steps 2 and 3 can’t be retried, because they sit outside the transaction (lacks atomicity), so any of them can fail or be skipped after a successful database commit, so the change is made but its side effects are not executed.&lt;/p&gt;

&lt;p&gt;Furthermore, the user dealing with tasks needs to wait for the endpoint to finish caching-related work and WebSockets broadcasting, and any fail happened to one of them will make the endpoint fails, even the operation on task has been done successfully on database.&lt;/p&gt;

&lt;p&gt;Also there is &lt;strong&gt;dual-write problem&lt;/strong&gt;. Executing the side effects are additional operations next to the database change inside the endpoint. If the endpoint commits and then invalidates the cache and then publishes to the board clients via WebSockets, a crash in between saves the task to the database but loses its side effects.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Solution: Transactional Outbox Pattern
&lt;/h3&gt;

&lt;p&gt;The Outbox pattern fixes it: the endpoint writes the resource change and data required to execute side effects in a single row (in an outbox table) in the same transaction on database, so the side effects and outbox row exists if and only if the change also exists.&lt;/p&gt;

&lt;p&gt;A separate relay (background job that continuously polls the &lt;code&gt;outbox&lt;/code&gt; table and perform a job like executing the side effects or publishing to the stream) reads unpublished outbox rows and performs the changes on the other systems. If the relay crashes, the rows stay in the table and side effects are executed by the relay after restart.&lt;/p&gt;

&lt;p&gt;Delivery of the side effect is therefore &lt;strong&gt;at-least-once&lt;/strong&gt;: if the relay processed/executed the side effect and crashes before marking the row as published, it executes the same side effect again after restart. Consumers must tolerate duplicates (should be idempotent) as the same side effect can be executed more than once.&lt;/p&gt;

&lt;h4&gt;
  
  
  Enhancement on Outbox Table: Partial Indexing
&lt;/h4&gt;

&lt;p&gt;The outbox table contains partial index on pending rows, for faster retrieval, considering only the pending side outbox rows, introducing some benefits:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Smaller index: Processed events don't occupy index space (Space efficiency).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Faster queries: The database searches a smaller index when retrieving pending events.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lower write overhead: Changes to rows that don't satisfy the predicate don't require maintaining entries in this index.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better cache efficiency: A smaller index is more likely to fit in memory so Postgres can cache it for faster retrieval.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Both full and partial indexes support the pending-events query, but the partial index avoids storing entries for the processed events.&lt;/p&gt;

&lt;p&gt;The database can use the partial index directly to locate pending events without bothering for processed events (limiting the search space hence reducing the latency).&lt;/p&gt;

&lt;p&gt;The Outbox is about correctness: after a crash, no DB-saved write loses its side effects (which is publishing an event to the stream in event-driven architecture).&lt;/p&gt;

&lt;p&gt;Simply: one extra INSERT in the transaction, and all side effects leave the endpoint.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Impact
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The P95 latency reduced by about 13%, it is not a big percentage but remember that I have only two &lt;strong&gt;light&lt;/strong&gt; side effects which are broadcasting and cache invalidation, in more complicated system these side effects may be much larger and take more time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I recorded &lt;strong&gt;ZERO&lt;/strong&gt; lost side effects while achieving the decoupling between the request and side effects failure or latency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The relay automatically processed/delivered 121 pending side effects from injected 60-second Redis outage/failure, in around 1.5 seconds from recovery. Before outbox, the request was staying 4 seconds when the Redis is down, and then it fails though the operation is done successfully and the issue is only in the side effect.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Some Trade-offs:
&lt;/h3&gt;

&lt;p&gt;Delivery of the side effect is now &lt;strong&gt;eventual&lt;/strong&gt;, there is a delay by 100ms (the relay sleeping time between polls) also more computations like fetching the outbox rows and loop on them.&lt;/p&gt;

&lt;p&gt;Ensuring "Freshness over liveness": the relay deletes the cache key before broadcasting, so a client that refetches after a message never reads a stale cached board (the broadcast waits for the cache delete). The cost of this is liveness: while Redis is down no broadcasts go out, so other users don’t see updates live, though a manual refetch still reads from the database (as fetching from cache is skipped as the caching server is down). Separately, one failing row blocks the rows behind it (head-of-line blocking).&lt;/p&gt;




&lt;h2&gt;
  
  
  Event-Driven Architecture (Asynchronous Communication via Messaging)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Why Outbox is Not Enough?
&lt;/h3&gt;

&lt;p&gt;What’s still wrong after the outbox: one relay runs both side effects in sequence. A stuck row blocks every row behind it, the row can be stuck as the cache invalidation and the broadcast can’t fail or retry separately, also without EDA and a third reaction (notifications) means modifying the relay logic. Simply, we decoupled the request path from side effects, but the consumers are still tightly coupled.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;

&lt;p&gt;With events, the endpoint records that something happened (e.g. &lt;code&gt;task_updated&lt;/code&gt;) which means &lt;strong&gt;publishing the event&lt;/strong&gt; and then the API responds to the user, without performing any inline side effects inside the endpoint.&lt;/p&gt;

&lt;p&gt;Two independent consumers react to this event:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cache consumer: invalidates the key.&lt;/li&gt;
&lt;li&gt;Broadcast consumer: pushes to board subscribers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So there is a stream with multiple consumer groups, every consumer group for a single side effect, so there is a group for WebSocket broadcasting and another one for cache invalidation.&lt;/p&gt;

&lt;p&gt;The request is faster, because it no longer waits. It is also safer, because a slow or failing side effect can’t fail a request whose task operation is already processed successfully.&lt;/p&gt;

&lt;p&gt;Trade-off: The side effects now happen after the response, so the system is &lt;strong&gt;eventually consistent&lt;/strong&gt;: a user who saves a task and immediately refetches may read stale cached data until the cache consumer runs.&lt;/p&gt;

&lt;p&gt;There is also a dual-write problem that is writing the change to database and publishing the event to the broker, so we still need &lt;strong&gt;transactional outbox pattern&lt;/strong&gt; here also, that commits the task write and the event in one row combining the database change with the publishing for the event in one atomic transaction.&lt;/p&gt;

&lt;p&gt;The relay here should just publish the message to the stream instead of doing the side effects directly.&lt;/p&gt;

&lt;p&gt;The value here is the design, with no big number or optimization. The core benefit is that a failing consumer no longer blocks the other (in the outbox-only relay, one stuck row blocked both), and a message that is unacknowledged is retried (even if it is done, this is at-least-once delivery).&lt;/p&gt;

&lt;h3&gt;
  
  
  Complete Event-Driven Pipeline for Task Write
&lt;/h3&gt;

&lt;p&gt;When any task write happens there is a flow of operations happens regarding this event:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The edit and its outbox record goes to database in a single transaction (atomicity).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The relay takes these undelivered records, and adds to a specific stream (that is append-only log, and can be trimmed) called &lt;code&gt;task:events&lt;/code&gt;, and each message in the stream get a &lt;code&gt;message_id&lt;/code&gt;. Then the relay marks the outbox record as published only after adding to the stream successfully, so this is the first layer of &lt;strong&gt;at-least-once delivery&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The cache and WebSocket broadcasting consumer groups independently read undelivered messages from the &lt;code&gt;task:events&lt;/code&gt; stream. When Redis delivers a message to a group, it records the message ID in that group's Pending Entries List (PEL) until the consumer explicitly acknowledges it (&lt;code&gt;XACK&lt;/code&gt;). Because my consumers code acknowledge messages &lt;strong&gt;after&lt;/strong&gt; executing their side effects, a crash between completing the work and sending the &lt;code&gt;ACK&lt;/code&gt; leaves the message &lt;strong&gt;delivered-but-unacknowledged&lt;/strong&gt;, causing it to be retried on recovery as it is considered pending. This provides a second layer of &lt;strong&gt;at-least-once delivery&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Choosing Streams for EDA
&lt;/h3&gt;

&lt;p&gt;There are three models of asynchronous communication (messaging):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The Message Queues (RabbitMQ): this can be used actually and there is no problems within my scope, exchange can be used to achieve the fan-out behavior by copying to multiple queues. I ruled out it just to save the time of setup as it would not pay off.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Publishing and Subscribing (Fire-and-Forget): this model has a main flaw which is if the subscriber is down at the moment of publishing, the message/event goes away. In my case this is wrong behavior as if the downstream service for side effect is down, the side effect should be processed once the service recovers. So we need some sort of saving the message for later processing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Streams (Redis Streams &amp;amp; Kafka): Stream brokers save the messages/events. Consumer groups let the cache and broadcast consumers each read every event independently, acknowledge it, and re-read unacknowledged events after a crash.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I did not choose Kafka as it is more complicated and introduces solutions for problems I do not have now or they are not important.&lt;/p&gt;

&lt;h3&gt;
  
  
  Weakness Points in the Project that are Accepted Consciously
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Caching is Not Suitable to be a Consumer Group in EDA
&lt;/h4&gt;

&lt;p&gt;I am learning event-driven architecture in this project, I believe that dealing with cache invalidation as a message that can be processed later is a bad idea. Caching is &lt;strong&gt;ephemeral&lt;/strong&gt; while streams are permanent.&lt;/p&gt;

&lt;p&gt;If a cache invalidation message gets delayed, duplicated, or re-delivered 10 minutes later, wiping a fresh cache entry harms performance and causes unnecessary database hits.&lt;br&gt;
A perfect example for this can be notifications that can be safely sent after 10-minute delay.&lt;/p&gt;

&lt;h4&gt;
  
  
  Precedence of Consumer Groups
&lt;/h4&gt;

&lt;p&gt;In EDA setup I did not control the precedence of cache invalidation over broadcasting. If the broadcasting happens first then anyone who receives the task update WebSockets frame/message and the UI is updated and then the user refreshes the page, they will receive the old board details as it is still cached, as the cache is invalidated after the broadcasting and there may be a delay.&lt;/p&gt;

&lt;h4&gt;
  
  
  Head-of-Line Blocking
&lt;/h4&gt;

&lt;p&gt;Because my consumer loop processes pending entries one by one, if it keeps failing on a specific message without a &lt;strong&gt;Dead-Letter Queue (DLQ)&lt;/strong&gt; or retry cap, that entry stays unacknowledged in the Pending Entries List (PEL) of that consumer and keeps getting retried, blocking every message behind that poisoned entry for that consumer until it is trimmed from the stream.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Looking back across all five parts of building &lt;strong&gt;Kanban Flow&lt;/strong&gt;, from modeling fractional indexing and RBAC in PostgreSQL, to setting up isolated integration tests, to tackling WebSocket security, token-bucket rate limiting, optimistic concurrency, Redis caching, the Transactional Outbox, and Redis Streams. It was learning how to evolve an architecture &lt;strong&gt;incrementally&lt;/strong&gt; and measure every decision against real trade-offs.&lt;/p&gt;

&lt;p&gt;Every upgrade solved a real bottleneck while introducing a new constraint:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Caching&lt;/strong&gt; cut P99 latency by ~81%, at the cost of managing staleness and invalidation races.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Transactional Outbox&lt;/strong&gt; eliminated dual-write failures and survived a 60-second Redis outage with zero lost side effects, at the cost of eventual delivery and relay head-of-line blocking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event-Driven Streams&lt;/strong&gt; decoupled consumers from one another, while introducing ordering and poison-message trade-offs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Building this system from scratch, breaking it under load and simulated outages, and documenting every decision along the way turned abstract system-design concepts into practical instincts. Thanks for following along through the series, if you have feedback, questions, or ideas for taking it further, drop a comment below!&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>performance</category>
      <category>eventdriven</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Part 4: Problems and Decisions</title>
      <dc:creator>Mazen Aly Abdelfattah</dc:creator>
      <pubDate>Wed, 21 Oct 2026 16:36:12 +0000</pubDate>
      <link>https://dev.to/mazen-13/part-4-problems-and-decisions-2f6e</link>
      <guid>https://dev.to/mazen-13/part-4-problems-and-decisions-2f6e</guid>
      <description>&lt;h2&gt;
  
  
  Before Real-Time Behavior
&lt;/h2&gt;

&lt;p&gt;The foundation of Kanban Flow and the required real-time behavior, is having all the required RESTful API endpoints, these endpoints are what we build on them the real-time behavior, they are the main way to access the data in the system and manipulate it.&lt;/p&gt;

&lt;p&gt;The real-time behavior exists in viewing the details of boards, so we will use it mainly in viewing updates, but the create, update and delete operations will be done over HTTP via REST.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why WebSockets Protocol
&lt;/h3&gt;

&lt;p&gt;One solution rather than WebSockets is &lt;strong&gt;continuous polling&lt;/strong&gt;, it is simply using the same restful API and just repeatedly send requests to check any changes happen, and if a change is detected then new data is rendered to the client, this introduces delay by the time between each poll. This delay is structural as in standard HTTP only the client can initiate a request, so the server has no way to notify a client of a change and the client must keep asking. Polling can give the real-time feel by polling very aggressively, but this consumes resources heavily.&lt;br&gt;
Furthermore, polling for every connected user that makes the cost grows at scale when users increase due to continuous processing for requests to determine whether there is a change or not.&lt;/p&gt;

&lt;p&gt;Also with continuous polling you're holding a TCP socket open (opened connection to avoid continuous handshakes and tearing down on every single polling request) on the server per client (HTTP/1.1 Persistent Connections), which is same resource cost as a WS connection, but now you're polling pointless empty responses across it instead of only sending data when something actually changes. So continuous keep-alive polling pays WebSockets TCP connection cost and still wastes bandwidth and CPU on empty "nothing changed" round trips. WebSockets is strictly better: same held-open TCP connection cost, but zero waste. It gives the ability for the server to push the changes to the client just when something is changed.&lt;/p&gt;




&lt;h3&gt;
  
  
  Preserving State
&lt;/h3&gt;

&lt;p&gt;The WebSocket connections are saved in memory as object per every connection per single user, so I pushed the connection objects to a dictionary that binds every connection with the user that opened it, and the same is made for boards, to know when board is changed, which users to push for them the change.&lt;/p&gt;

&lt;p&gt;Also till now I focus on building the system to work as one instance with no distributed states that are centralized and can be accessed from multiple instances.&lt;/p&gt;

&lt;p&gt;A single connection can be subscribed in at most one board, and single user can have many connections.&lt;/p&gt;




&lt;h3&gt;
  
  
  Problem of Database Connections
&lt;/h3&gt;

&lt;p&gt;WebSockets is stateful, so unlike REST, a session-scoped database session object would hold one DB connection open per WS connection for its entire lifetime which may exhaust the connection pool and the connections run out. I fixed this by scoping the session to just the auth-time DB lookup instead and delete it after usage, releasing the DB connection.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pushed Changes To Clients
&lt;/h2&gt;

&lt;p&gt;Refetching the boards on every change is bad idea, as if there are N concurrent users connected to the board and are viewing it, one change will trigger N requests to reload the board. The right decision here is to just broadcast deltas and every user build on the version that he has already loaded.&lt;/p&gt;

&lt;p&gt;Regarding how users are connected to the boards, I decided at first to close and reopen a WS connection every time the user navigates to a different board. Downsides: every navigation now pays a full handshake + auth-frame/auth-message round trip again. At scale, users switching boards frequently = exhausting the TCP sockets which are the underlying of websocket connections.&lt;/p&gt;

&lt;p&gt;Then I ruled out that, and decided to keep &lt;strong&gt;only one&lt;/strong&gt; WS connection open for the whole session (from login to logout/tab-close). When the user navigates to Board 1, client sends a small message over the existing connection: {"type": "subscribe", "board_id": 1}. Server adds that connection to a "Board 1 room." Navigate to Board 2, then client sends {"type": "unsubscribe", "board_id": 1} then {"type": "subscribe", "board_id": 2}. Same connection, just changes which "room" it's in. So, one persistent connection + "rooms"/subscriptions that are the users that any change on the subscribed board will be pushed for them.&lt;/p&gt;




&lt;h3&gt;
  
  
  Securing Endpoints with WebSockets Protocol
&lt;/h3&gt;

&lt;p&gt;With WebSockets, the browser's WebSocket API gives you no way to set custom headers on the handshake request unlike traditional RESTful endpoints, so I considered 3 choices, ruled out 2 and landed on the 3rd:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Sending the JWT as a query param:&lt;/strong&gt; then discovered that this may leak the JWT into server/proxy logs and browser history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Persisting the JWT as a cookie on the client side:&lt;/strong&gt; but since the browser auto-attaches cookies on every request to the domain regardless of origin, this option opens CSRF vulnerability, which is simply a malicious link can have JS script that requests the server and then it connects with the server and can do anything on behalf of the client. I believe that this can be mitigated but I decided not to continue with this solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Sending the JWT as the first frame/message after the upgrading the protocol:&lt;/strong&gt; this solution avoids the pitfalls in the previous two, here the JWT only travels once, as an explicit message/frame over an encrypted channel (via wss protocol), never touching a URL or relying on credentials that browsers send automatically. It has only one downside that is potentially exhausting resources, as a buggy or malicious client can open many upgraded connections and each connection consumes server resources and they remain unauthenticated, so it may cause DoS problem but this can be avoided by setting a timeout after the server accepts and upgrades the protocol from HTTP to WS and during this allowed period the client should send their JWT and authenticate, otherwise the connection automatically closes releasing the resources allocated for it.&lt;/p&gt;




&lt;h3&gt;
  
  
  Rate Limiting
&lt;/h3&gt;

&lt;p&gt;The system should have defense line against the buggy or malicious clients that sends too many messages, as messages mostly means queries that run on the database and resources consumption, so to prevent resource exhaustion we should maintain a limit for messages that a single client can send and after it, a rate limited message should be sent.&lt;/p&gt;

&lt;p&gt;I decided to set the limit on the user not the connection, so it can not get bypassed by simply opening multiple connections for the same user.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Algorithm
&lt;/h4&gt;

&lt;p&gt;My idea depends on &lt;strong&gt;tokens&lt;/strong&gt;, each token represents a unit that the client can spend for sending a message to the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fixed time window:&lt;/strong&gt; tokens are refreshed every X seconds. The client can send 5 messages right before X, the tokens are refreshed at second X, and it sends 5 more messages right after. So there are 10 messages in small window.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Token bucket (capacity 5, +1 token every 0.2s till reaches 5 tokens):&lt;/strong&gt; The system adds 1 token for the user every 0.2s, until reaches the limit of 5 tokens which is the &lt;strong&gt;bucket's capacity&lt;/strong&gt; (this prevents accumulating tokens and flooding the server with messages by a malicious or buggy client). This solution can still allow bursts (up to the bucket capacity) but it doesn't have the fixed-window boundary problem, here you can not send 10 messages in a small window.&lt;/p&gt;




&lt;h3&gt;
  
  
  Concurrent Updating and Lost Updates
&lt;/h3&gt;

&lt;p&gt;Two users open the same task, and one saves. The other user's screen never receives that update, because their connection dropped, they left an edit form open, or both saves were sent at the same moment. The second user then saves from the stale copy and overwrite the first user's change. No error is raised and the first user's work is lost silently while the change was intended to be on the stale version before updates of the first user.&lt;/p&gt;

&lt;h4&gt;
  
  
  Approaches to Fix
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Optimistic&lt;/strong&gt; concurrency control: that is allowing everyone edit freely and concurrently and only pays when a conflict actually occurs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pessimistic&lt;/strong&gt; concurrency control: that is &lt;strong&gt;locking&lt;/strong&gt; the updates, so no user can edit a task while there is another user is editing it. If edit stays for minutes due to any problem so others have to wait. It requires more handling to mitigate this like timeouts.&lt;/p&gt;

&lt;p&gt;Conflicts are rare, in pessimistic concurrency control the system pays that cost on every edit to prevent something that seldom happens. I chose to never make anyone wait, just update and if there is a conflict happened then notify that error happened and the user will try again, instead of waiting long time&lt;/p&gt;

&lt;h4&gt;
  
  
  Implementing Optimistic Concurrency Control
&lt;/h4&gt;

&lt;p&gt;Each task carries a version, and every edit sends back the version it was based on. The server applies the update only if that version still matches, then increments it. If it doesn't match, the edit was based on stale data, so the server rejects it with &lt;em&gt;409 Conflict&lt;/em&gt; and the client knows that he was editing a stale version.&lt;br&gt;
The check and the write happen in a single atomic SQL update statement that locks the database row for the duration of executing the update statement, so two simultaneous requests can never both pass (this is the Isolation principle in ACID principles that relational DBMS follow, which is update statements for the same data are not interfered).&lt;/p&gt;

&lt;p&gt;I decided to make only title and description edits are versioned. A move is a complete instruction ("put it in Done"), so last-write-wins is acceptable as there is no data loss. One known limitation in my idea is when two tasks are dropped into the same gap they get the same index, so their relative order becomes ambiguous. A unique constraint on (column, index) with retry would solve this, but I decided to not solve this problem as I want to focus on more important things in this project.&lt;/p&gt;

&lt;p&gt;I tested the concurrency via 20 requests overlapping once. So the server is flooded by 20 requests at the same time, and it only makes one update request passes and all the others get 409 Conflict. So I succeeded in controlling the concurrency.&lt;/p&gt;

</description>
      <category>api</category>
      <category>websockets</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Part 3: Automated Testing Setup</title>
      <dc:creator>Mazen Aly Abdelfattah</dc:creator>
      <pubDate>Fri, 28 Aug 2026 19:05:08 +0000</pubDate>
      <link>https://dev.to/mazen-13/part-3-automated-testing-setup-22h6</link>
      <guid>https://dev.to/mazen-13/part-3-automated-testing-setup-22h6</guid>
      <description>&lt;h2&gt;
  
  
  Current Situation
&lt;/h2&gt;

&lt;p&gt;Now I am building the CRUD API endpoints for the system, there is no WebSockets and no event-driven architecture and there is not any advanced concepts.&lt;/p&gt;

&lt;p&gt;I wanted to start setting up the testing environment and workflow from the beginning. Also I need to try &lt;strong&gt;Test-Driven Development&lt;/strong&gt;, so I am going to apply it at some parts in the application. Now the testing environment is completely ready and the first integration test is ready.&lt;/p&gt;




&lt;h2&gt;
  
  
  Unit and Integration Tests
&lt;/h2&gt;

&lt;p&gt;In this project I found that I need more &lt;strong&gt;integration tests&lt;/strong&gt;, actually in many situations I need to check what is the behavior of the endpoint at specific situations. So most of the tests will be like "simulate a client sending a request, then check the response and/or the database state.". Hence, there will be more integration tests than unit tests.&lt;/p&gt;

&lt;p&gt;I know this deviates from the classic &lt;strong&gt;testing pyramid&lt;/strong&gt;. However, given the nature of this codebase as its mainly a CRUD orchestration without huge complex business logic computations, leaning on integration tests makes more sense here than chasing the pyramid's default ratio.&lt;/p&gt;




&lt;h2&gt;
  
  
  Setting up the Testing Environment
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Tools
&lt;/h3&gt;

&lt;p&gt;First of all, I used &lt;em&gt;pytest&lt;/em&gt; as the testing framework that helps me write and run tests. I also need a way to send requests to my FastAPI app and get real responses back, so I used &lt;em&gt;httpx.AsyncClient&lt;/em&gt;, which calls the app's code directly in-process, simulating real HTTP requests without needing an actual running server or network layer that maps the HTTP requests to the actual code.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Testing Database Setup
&lt;/h3&gt;

&lt;p&gt;This is very important point, if the tests use the real production/development database, they will pollute data. So there must be a testing database that are made specifically for the tests to use, it should be a completely separate, throwaway database.&lt;/p&gt;

&lt;h4&gt;
  
  
  Test Containers
&lt;/h4&gt;

&lt;p&gt;On every run for the tests, we can start an actual Postgres Docker container that contains the testing database server. Then we run the existing migrations against the new server, so we get a new database server with a new database with the required schema (same as the production/development database) just for testing.&lt;/p&gt;

&lt;p&gt;To achieve this I used &lt;em&gt;testcontainers-postgres&lt;/em&gt; to spin up a real, &lt;strong&gt;temporary&lt;/strong&gt; Postgres Docker container once per test session (not per test, since that'd be slow). That is the separate database server that is thrown after every test session.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Overriding the Injected Database Dependency
&lt;/h3&gt;

&lt;p&gt;For now when FastAPI notices that an endpoint needs a database session, it injects one that is connected to the real database.&lt;/p&gt;

&lt;p&gt;What we need is to tell FastAPI to inject a session connecting to another database server which for testing.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Isolate the Tests
&lt;/h3&gt;

&lt;p&gt;We have to isolate the tests so each test sets its own data inside the database and then rolled back. We need every test to start clean, without leftover data from a previous test, so test A data changes never affect test B.&lt;/p&gt;

&lt;p&gt;This can be achieved by utilizing the &lt;strong&gt;Isolation&lt;/strong&gt; principle in ACID principles that PostgreSQL DBMS follows, stating that any uncommitted changes in a session are isolated and can not be visible by other sessions. So we just rollback any changes a test made so there is not any persisted durable data on the database, every test make its changes via an separate isolated session and never really commits inside the database (and any commits made during the test are absorbed by an outer transaction that is always rolled back after each test, commits are considered &lt;strong&gt;savepoints&lt;/strong&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  Interesting Issue Faced Me
&lt;/h3&gt;

&lt;p&gt;One subtle issue I hit: my connection pool (that managed by test_engine object) was session-scoped for performance, but &lt;em&gt;pytest-asyncio&lt;/em&gt; creates a new event loop per test method by default. Async database connections are tied to the event loop that created them, so reusing a reserved connection across tests (across event loops) caused failures. The fix was configuring &lt;em&gt;pytest-asyncio&lt;/em&gt; to share a single event loop for the whole session, matching the connection pool's lifetime, so there is only one event loop that will use connections for the single test engine.&lt;/p&gt;

</description>
      <category>testing</category>
    </item>
    <item>
      <title>Part 2: Designing the Database Schema and Data Representation</title>
      <dc:creator>Mazen Aly Abdelfattah</dc:creator>
      <pubDate>Mon, 17 Aug 2026 12:51:47 +0000</pubDate>
      <link>https://dev.to/mazen-13/part-2-designing-the-database-schema-1ck1</link>
      <guid>https://dev.to/mazen-13/part-2-designing-the-database-schema-1ck1</guid>
      <description>&lt;h3&gt;
  
  
  Main Entities
&lt;/h3&gt;

&lt;p&gt;While designing the database through an ERD, I found that the main entities are &lt;strong&gt;users&lt;/strong&gt;, &lt;strong&gt;boards&lt;/strong&gt; (that represent projects), &lt;strong&gt;columns&lt;/strong&gt; (that represent stages) and &lt;strong&gt;tasks&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I designed the system's data model to be user-owned data, so every user is admin of the boards that are created by them, and there is no admin role that give full control on all the data.&lt;/p&gt;

&lt;h4&gt;
  
  
  Database Relational Schema
&lt;/h4&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%2Frm9cmg4qvdzvi8qdxuz2.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%2Frm9cmg4qvdzvi8qdxuz2.png" alt="Database Relational Schema"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Roles
&lt;/h3&gt;

&lt;p&gt;I decided to have four roles: &lt;strong&gt;Owner&lt;/strong&gt;, &lt;strong&gt;Manager&lt;/strong&gt;, &lt;strong&gt;Assignee&lt;/strong&gt; and &lt;strong&gt;Viewer&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Owner:&lt;/strong&gt; is given automatically to the user that created the board/project, allowing them to perform project-level CRUD operations in addition to CRUD operations against the columns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manager:&lt;/strong&gt; allows performing task-level CRUD operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assignee:&lt;/strong&gt; can only change the status of a task (by transferring it from a column to another)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Viewer:&lt;/strong&gt; can not take any action, can only view the board details (giving the access to the project data).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We need another table to store the role of each user per board/project, so &lt;strong&gt;user_board_role table&lt;/strong&gt; is the only place where the permissions/roles are saved.&lt;/p&gt;

&lt;p&gt;So, totally we need 5 tables: users, boards, columns, tasks and user_board_role&lt;/p&gt;

&lt;p&gt;Also we need a table to store the events that happens, but this will be added when we setup the event-driven architecture for the system.&lt;/p&gt;




&lt;h3&gt;
  
  
  Handling the Order of Tasks in a Column
&lt;/h3&gt;

&lt;p&gt;In the tasks table we need to preserve the order of the tasks, so when retrieving the tasks for a specific column, we need to sort them by their order.&lt;/p&gt;

&lt;h4&gt;
  
  
  Possible Inefficient Solution
&lt;/h4&gt;

&lt;p&gt;A naive solution for this is to have a column inside the tasks table that stores a number representing the order of the task (index of the task).&lt;br&gt;
However, this solution is inefficient as when we need to change the order of a specific task, we need to update all the tasks between its old position and new position and increase the number that represents their order by 1.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;time complexity&lt;/strong&gt; of this algorithm is O(n), as for each task we need to change we have to loop over all the tasks between its new and old positions and update them.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Chosen Efficient Solution
&lt;/h4&gt;

&lt;p&gt;The more efficient approach is to store the order as a decimal (fractional index). So when we need to change the position of a specific task, all we need is to find a decimal between the index of the previous and next task to be the new index of the transferred task. We sort the tasks according to their index to get a sorted list of tasks.&lt;/p&gt;

&lt;p&gt;For example, task A has index 1, task B has index 2, dropping a new task between them requires calculating a new index for the new task that is 1.5.&lt;/p&gt;

&lt;p&gt;Its time complexity is only O(1), so it is very efficient. However, after many operations we may face precision problems, the solution is to &lt;strong&gt;rebalance&lt;/strong&gt; when two adjacent indices get too close in value to fit a new decimal between them. Rebalancing is just looping over the tasks and assigning them integer-valued indices.&lt;/p&gt;

</description>
      <category>database</category>
      <category>design</category>
    </item>
    <item>
      <title>Part 1: Determining What to Build</title>
      <dc:creator>Mazen Aly Abdelfattah</dc:creator>
      <pubDate>Sun, 16 Aug 2026 17:03:35 +0000</pubDate>
      <link>https://dev.to/mazen-13/part-1-choosing-the-idea-3c92</link>
      <guid>https://dev.to/mazen-13/part-1-choosing-the-idea-3c92</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This is the first post of a series that documents the whole journey of my third major production-grade project. It is going to contain the whole process from an idea in my mind to a &lt;strong&gt;fully deployed web application&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Determining What I'm Going to Build
&lt;/h2&gt;

&lt;p&gt;I wanted to tackle a new challenge centered around real-time systems and complex state management. I also wanted to explore caching strategies and other infrastructure concerns like event-driven architecture.&lt;/p&gt;

&lt;h3&gt;
  
  
  The First Choice, and Why I Passed on It
&lt;/h3&gt;

&lt;p&gt;My first idea was a live collaborative text editor as a real-time application. But after researching the problem space, I realized that its core engineering challenges (like document synchronization, cursor synchronization, and conflict resolution) are highly specialized problems that are not closely aligned with the areas I want to grow in: backend engineering, system design, and architectural decision-making.&lt;/p&gt;

&lt;p&gt;More importantly, these problems are already solved by mature libraries such as Yjs, paired with editor frameworks like Lexical or Monaco. In a real-world project, integrating these libraries is the right engineering decision rather than spending significant time reimplementing this highly specialized logic, which offers limited learning beyond that narrow domain.&lt;br&gt;
As a result, the project's primary distinguishing feature, that is live collaborative editing, is provided by third-party software.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Second Choice, and Why It Was The Right Fit
&lt;/h3&gt;

&lt;p&gt;After some searching, I found that a collaborative project management platform is a good choice. It naturally introduces a wide range of engineering challenges that add real value to the system. Unlike a collaborative text editor, these challenges arise from the domain itself rather than being artificially introduced to justify additional technologies. They include caching, event-driven workflows, notifications, background processing, authorization, audit logging, search, and real-time synchronization, all working together to support the final product. These are exactly the kinds of problems encountered in production backend systems, providing far more opportunities to practice system design and architectural decision-making.&lt;/p&gt;

&lt;p&gt;In the end, my goal wasn't simply to build a real-time application. It was to build a system whose domain inherently demands diverse architectural decisions and production-grade engineering challenges, allowing me to learn far more than a project centered around a single specialized problem.&lt;/p&gt;




&lt;h2&gt;
  
  
  Choosing the Web Framework
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Why not ASP.NET
&lt;/h3&gt;

&lt;p&gt;I had already built two projects using ASP.NET Core and the .NET ecosystem, so I wanted this project to expose me to a different ecosystem.&lt;/p&gt;

&lt;p&gt;I chose Python because it is widely used beyond web development in areas such as automation, AI, and data engineering. Rather than building another project with tools I already knew well, I wanted this project to broaden my technical perspective.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why FastAPI
&lt;/h3&gt;

&lt;p&gt;It's a modern, asynchronous web framework with first-class WebSocket support, making it a natural fit for building real-time applications. Unlike Django and Flask, which require additional libraries or extensions to build WebSocket-based applications, FastAPI provides this capability out of the box.&lt;/p&gt;

&lt;p&gt;Furthermore, it has a significantly lighter configuration model than ASP.NET Core, allowing me to move from project setup and infrastructure configuration to implementing application logic much more quickly. This provides a streamlined development experience with minimal boilerplate, enabling me to focus more on the engineering challenges of the project rather than framework configuration. It also provides many capabilities out of the box, including dependency injection, automatic request validation, and OpenAPI documentation with very little configuration in addition to being a high-performance web framework.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;p&gt;In the next post, I'll dive into the details of the project, some capabilities of the system and database design.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>softwaredevelopment</category>
      <category>webdev</category>
    </item>
    <item>
      <title>LINTelligent — AI-Integrated service for code linting and reviewing with MCP server</title>
      <dc:creator>Mazen Aly Abdelfattah</dc:creator>
      <pubDate>Mon, 20 Jul 2026 07:17:07 +0000</pubDate>
      <link>https://dev.to/mazen-13/lintelligent-ai-integrated-service-for-code-linting-with-mcp-server-4ke4</link>
      <guid>https://dev.to/mazen-13/lintelligent-ai-integrated-service-for-code-linting-with-mcp-server-4ke4</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This is a post I need to share with you my thought process, decisions that I took in designing the service, and share new things that I learned. I hope anyone can benefit from my words or inspire anyone with my ideas and what I learned so we both can grow. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/mazenaly256" rel="noopener noreferrer"&gt;
        mazenaly256
      &lt;/a&gt; / &lt;a href="https://github.com/mazenaly256/LINTelligent" rel="noopener noreferrer"&gt;
        LINTelligent
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      AI-integrated backend service for code linting (i.e. analyzing code for issues), with an accompanying MCP server for AI-agent integration.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;LINTelligent&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;AI-integrated backend service for code linting (i.e. analyzing code for issues), with an accompanying &lt;strong&gt;MCP server&lt;/strong&gt; for AI-agent integration.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/LINTelligent/actions/workflows/ci-pipeline.yml/badge.svg"&gt;&lt;img src="https://github.com/mazenaly256/LINTelligent/actions/workflows/ci-pipeline.yml/badge.svg" alt="CI Pipeline Building and Testing"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Overview&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;A code snippet is submitted in a linting/reviewing request, either as a direct snippet in the request body or via a public GitHub file URL.&lt;/p&gt;
&lt;p&gt;Once the linting request reaches the system, &lt;em&gt;LINTelligent&lt;/em&gt; saves its details in the database and enqueues a background job to the job queue for handling this request, then immediately returns 202 Accepted. If a GitHub URL was provided, the code is first fetched, then the review job runs, otherwise the review job runs directly on the submitted code snippet.&lt;/p&gt;
&lt;p&gt;After that, a worker picks up the job from the job queue and processes it, it fetches the code from the GitHub URL (if exists) then it calls the configured LLM provider with the request details and receive the review report of issues, then updates…&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/mazenaly256/LINTelligent" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Fun Fact:&lt;/strong&gt; While I was testing it and request reviews on some code snippets from my previous project (Cinema Seat Reservation System), LINTelligent helped me discover a critical bug related to resource wasting as I did not dispose some objects that results in memory leak.&lt;/p&gt;




&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;LINTelligent is a service that takes a code snippet as an input, and analyze it and return the issues in this code snippet.&lt;/p&gt;

&lt;p&gt;User can either use it directly by requesting the API endpoints, or via an AI agent through the MCP server.&lt;/p&gt;

&lt;h3&gt;
  
  
  The workflow
&lt;/h3&gt;

&lt;p&gt;User sends a review request, the service stores a new review with the code snippet in the database with status 'Pending', then it stores in the queue the methods that should be called to process this job/request with the related arguments for this request, then the service immediately returns 202 Accepted HTTP response so the client do not wait too much, &lt;strong&gt;detaching the client from long-running background processing&lt;/strong&gt;.&lt;br&gt;
As the jobs are saved in the queue, a worker thread picks up a job of a review request from the queue and process it, calling the methods that are stored in database as the processing way for this job. The worker sends the review request with the &lt;strong&gt;system prompt&lt;/strong&gt; and the code snippet (user message) to the LLM and receives the response, then the service persists the review report that LLM returned into the database, then it notifies the user that the the request processing has been finished.&lt;/p&gt;


&lt;h2&gt;
  
  
  System Architecture and Design
&lt;/h2&gt;

&lt;p&gt;Lets start with a basic system architecture diagram with the data flow for the service.&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%2Fkbjf6w5rsutk4dswkcee.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%2Fkbjf6w5rsutk4dswkcee.png" alt="Basic System Architecture Diagram" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Asynchronous Processing
&lt;/h3&gt;

&lt;p&gt;I designed this system to handle the requests in an asynchronous way, so the requests are processed in the background and then the user gets notified on completion via webhook. To achieve this I used &lt;strong&gt;message/job queue pattern&lt;/strong&gt;, as shown in the diagram, the service stores the review request as a job in the job queue, and then a worker execute that job by calling the LLM, getting the review report then notify the user via webhook.&lt;/p&gt;
&lt;h4&gt;
  
  
  Queue Pattern
&lt;/h4&gt;

&lt;p&gt;The queue pattern is simply a pattern where a &lt;strong&gt;producer&lt;/strong&gt; puts messages/jobs in a &lt;strong&gt;queue&lt;/strong&gt;, and then a consumer/worker (that can be either on another machine or just another thread) that reads that job/message and executes some logic to process them.&lt;/p&gt;

&lt;p&gt;In our case, the &lt;strong&gt;producer is obviously the service&lt;/strong&gt;. Inside the endpoint of requesting a new review, it stores a job in a queue.&lt;/p&gt;

&lt;p&gt;Now we need a queue that persists the jobs/messages so the workers can take and process them one by one. Also, we need the workers themselves.&lt;/p&gt;
&lt;h4&gt;
  
  
  Hangfire Decision
&lt;/h4&gt;

&lt;p&gt;Hangfire is a technology that provides the queue and persist the jobs data in a database (stores the details about the method that is required to be called to process some logic).&lt;/p&gt;

&lt;p&gt;Also Hangfire reserves a number of threads form the thread pool of the application to create the workers pool, these are threads that only execute the enqueued jobs, each worker polls for jobs from the database and when there is a job it directly execute it.&lt;/p&gt;

&lt;p&gt;Because of that, I favored using Hangfire to implement this pattern. It is simpler and provide all-in-one solution for me and at my scale I believe that it is more than sufficient.&lt;/p&gt;

&lt;p&gt;Other choices would be more complicated and will not pay off at my scale. I could implement this using a separate queue on another server via technologies like &lt;strong&gt;RabbitMQ&lt;/strong&gt; or any similar message brokers but this will require having separate workers also that will listen to the messages or poll for them and implement the logic.&lt;/p&gt;


&lt;h3&gt;
  
  
  Handling User-Supplied URLs Safely (SSRF Mitigation)
&lt;/h3&gt;

&lt;p&gt;When I added the ability to submit a GitHub file URL instead of pasting code directly, I ran into a security problem that's easy to miss: SSRF, or Server-Side Request Forgery.&lt;/p&gt;

&lt;p&gt;The naive version of this feature is simple, take the URL the user gives you, and have your server fetch it. The problem is that "your server fetches it" part. The request doesn't come from the user's browser, it comes from your backend, using your backend's network position. If you don't restrict what URLs are allowed, an attacker isn't limited to real GitHub files, they can point your server at internal services, cloud metadata endpoints, or anything else your server can reach that the hackers normally couldn't.&lt;/p&gt;

&lt;p&gt;So a URL field isn't just an input validation problem, it's a "what is my server willing to do on someone else's behalf" problem.&lt;/p&gt;

&lt;p&gt;For handling this, I enforced exact host match on &lt;code&gt;raw.githubusercontent.com&lt;/code&gt;, and prevented any redirections when requesting the submitted URL.&lt;/p&gt;


&lt;h3&gt;
  
  
  Integration with LLM and controlling the usage cost
&lt;/h3&gt;

&lt;p&gt;When you call the LLM to integrate it in your system, you don't just send the code. You send two things every single call:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. System Prompt&lt;/strong&gt;&lt;br&gt;
This is your instructions to the LLM, it never changes between calls. It tells the LLM who it is (the persona) and what to do. It is something like:&lt;br&gt;
"You are a code review assistant. Analyze the code you receive and return ONLY a JSON object with an issues array. Each issue must have: line number, severity (error/warning/info), type, and message. Never explain yourself. Never add text outside the JSON."&lt;br&gt;
This is how you force structured output, short and structured JSON and nothing else. Without it, the AI would respond in plain English like a human, and this is hard to process in the code also it makes your output tokens explode and thereby your cost.&lt;/p&gt;

&lt;p&gt;That's exactly why the system prompt exists, to say "return JSON only, no explanations", it's not just about structure, it's also cost control. Furthermore, you handle edge cases through the system prompt, like telling the LLM that if the inferred language of the code snippet does not match the language field that is sent with the request, then return language mismatch, instead the LLM returns many compilation errors as the language is different, which is unnecessary cost.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. User Message&lt;/strong&gt;&lt;br&gt;
This is the actual code the user submitted, and LLM deals with it according to the instructions in the system prompt. This changes every call according to the request data, this is the "What to handle". System prompt is the "How to handle".&lt;/p&gt;


&lt;h3&gt;
  
  
  Software Design (Architecture and Patterns)
&lt;/h3&gt;

&lt;p&gt;I was building my application without caring about this at the beginning, but when I needed to perform &lt;strong&gt;Unit Testing&lt;/strong&gt;, I realized that my code is tightly coupled and needs refactoring. So, in the next sections I will specify what did I design and build exactly.&lt;/p&gt;
&lt;h4&gt;
  
  
  Clean Architecture
&lt;/h4&gt;

&lt;p&gt;When thinking in this project, it appears that it aligns well with the Clean Architecture. It has external dependencies like database, LLM, webhook notifying and GitHub integration, so they should be isolated in &lt;strong&gt;Infrastructure Layer&lt;/strong&gt;. Inside this layer, I designed it to contain implementations for LLM clients that their job is only to communicate with LLM providers and it absolutely never do anything related to the business logic, and to contain implementations for repositories. Then I built an &lt;strong&gt;Application Layer&lt;/strong&gt; that orchestrate the business workflow and decisions, so it talks to the infrastructure layer without being dependent on it, achieving loose coupling between layers.&lt;/p&gt;

&lt;p&gt;This aligns with the &lt;strong&gt;Single Responsibility Principle&lt;/strong&gt;. Also, it makes the codebase more &lt;strong&gt;testable&lt;/strong&gt; as it isolates the client and make all the business workflow orchestration only inside the Application Layer. Now if I want to write unit tests, I will never care about the client as it is simply integration details, no need to consider them in unit testing.&lt;/p&gt;
&lt;h4&gt;
  
  
  Adapter design pattern
&lt;/h4&gt;

&lt;p&gt;Appears in LLM client. It adapts the different responses of different LLMs, and give standard response to the Application Layer. So, the client itself adapts the internal shape of data to be compatible with the standard DTO defined inside the Application Layer.&lt;/p&gt;
&lt;h4&gt;
  
  
  Repository Design Pattern
&lt;/h4&gt;

&lt;p&gt;Generally, having repository pattern with EF Core is actually a bad practice. The truth is EF Core itself applies repository pattern and unit of work pattern. So if you tried to implement repository pattern, it will be just wrapper methods over the EF Core, and it will hide the power of using EF Core directly and controlling the queries and commands via LINQ.&lt;/p&gt;

&lt;p&gt;But in my case, I decided to have a repository pattern, actually I felt that it is important. In my case I just need some operations like: changing status, saving review result in the database or get review by ID. I did not need to delete anything or to generally update the records, I just needed to update specific fields and add new or get by ID, so in my case I found that it is better to have this layer that will introduce to me better API to use inside the application layer and fits better to my needs. Furthermore, the repository pattern here to achieve more loose coupling, and higher testability by using the interfaces and mocking, so it is a trade-off.&lt;/p&gt;


&lt;h2&gt;
  
  
  Integrating with the AI Agent
&lt;/h2&gt;

&lt;p&gt;I wanted to explore what it means to make a service agent-ready, not just API-ready. I wanted to make the AI agent to become another consumer of the API, so not only frontend clients can use my service via APIs, also the AI agents via &lt;strong&gt;MCP Server&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is MCP Server
&lt;/h3&gt;

&lt;p&gt;AI Agent (more accurately, Host) contains two relevant pieces: the LLM (that is responsible for the reasoning) and the Client (that communicates with MCP servers).&lt;/p&gt;

&lt;p&gt;The MCP server is essentially a layer for AI agents to use the API. REST API endpoints are great for developers building frontends that consume the API directly, but if you want AI agents to call your API endpoints, then you need this extra layer, the MCP server, communicating with AI agent either over stdio or HTTP, depending on whether it runs locally on the same machine as the agent, or the server is deployed online.&lt;/p&gt;
&lt;h4&gt;
  
  
  Docker Image
&lt;/h4&gt;

&lt;p&gt;Docker image of the local MCP server is available in the packages section in the repository.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/mazenaly256" rel="noopener noreferrer"&gt;
        mazenaly256
      &lt;/a&gt; / &lt;a href="https://github.com/mazenaly256/LINTelligent" rel="noopener noreferrer"&gt;
        LINTelligent
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      AI-integrated backend service for code linting (i.e. analyzing code for issues), with an accompanying MCP server for AI-agent integration.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;LINTelligent&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;AI-integrated backend service for code linting (i.e. analyzing code for issues), with an accompanying &lt;strong&gt;MCP server&lt;/strong&gt; for AI-agent integration.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/LINTelligent/actions/workflows/ci-pipeline.yml/badge.svg"&gt;&lt;img src="https://github.com/mazenaly256/LINTelligent/actions/workflows/ci-pipeline.yml/badge.svg" alt="CI Pipeline Building and Testing"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Overview&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;A code snippet is submitted in a linting/reviewing request, either as a direct snippet in the request body or via a public GitHub file URL.&lt;/p&gt;
&lt;p&gt;Once the linting request reaches the system, &lt;em&gt;LINTelligent&lt;/em&gt; saves its details in the database and enqueues a background job to the job queue for handling this request, then immediately returns 202 Accepted. If a GitHub URL was provided, the code is first fetched, then the review job runs, otherwise the review job runs directly on the submitted code snippet.&lt;/p&gt;
&lt;p&gt;After that, a worker picks up the job from the job queue and processes it, it fetches the code from the GitHub URL (if exists) then it calls the configured LLM provider with the request details and receive the review report of issues, then updates…&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/mazenaly256/LINTelligent" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h3&gt;
  
  
  Communication between AI Agent and MCP Server
&lt;/h3&gt;

&lt;p&gt;AI agent (especially the Client) does the MCP handshake via 'initialize' request to get more info about the MCP server and its capabilities then it sends 'tools/list' to know each server's tools, and the same with prompts with 'prompts/list' and resources with 'resources/list' so agent can can invoke those things when it needs. All happening at connection startup, before any actual request for any specific resource, prompt or tool. The actual request happens after that, when LLM decides to use any thing from these available tools during the reasoning loops.&lt;/p&gt;




&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;One of the things I learned in this project is what loose coupling really means in practice, I started with a tightly-coupled codebase in the beginning then I had to refactor the whole codebase and architecture to make it testable and write good unit tests.&lt;/p&gt;

&lt;p&gt;I learned many things from this project and shared with you some of them, I hope anyone can learn anything from this blog post or even take a glimpse on something new that can explore more deeply.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>mcp</category>
      <category>backend</category>
      <category>api</category>
    </item>
    <item>
      <title>Cinema Seat Reservation System — Part 3: Problems, Decisions and Some Areas Of Improvement</title>
      <dc:creator>Mazen Aly Abdelfattah</dc:creator>
      <pubDate>Tue, 14 Jul 2026 09:11:09 +0000</pubDate>
      <link>https://dev.to/mazen-13/cinema-seat-reservation-system-part-3-problems-decisions-and-some-areas-of-improvement-1n65</link>
      <guid>https://dev.to/mazen-13/cinema-seat-reservation-system-part-3-problems-decisions-and-some-areas-of-improvement-1n65</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In the two previous parts, I finished sharing my main checkpoints while I was building the system till I deployed it. Today, I need to share two interesting problems that faced me and how I took decisions to solve them. I hope someone can benefit from them.&lt;br&gt;
Also, I will mention the areas of improvement in the system, how it can be better and considering their negative consequences on the system. &lt;em&gt;System design is all about Trade-offs&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You can find more decisions regarding the system in &lt;code&gt;/docs/decisions/&lt;/code&gt; folder on GitHub repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/mazenaly256" rel="noopener noreferrer"&gt;
        mazenaly256
      &lt;/a&gt; / &lt;a href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System" rel="noopener noreferrer"&gt;
        Cinema-Seat-Reservation-System
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Cloud-native microservices-based cinema seat reservation system developed. Designed for modularity and scalability.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Cinema Seat Reservation System&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;A cloud-native, microservices-based ecosystem developed in ASP.NET Core with REST APIs. This system features deliberate design decisions optimized for modularity, scalability and resilience — implementing proven distributed systems patterns such as Retries and Circuit Breakers and Request Timeouts alongside automated CI pipelines and manual deployment workflow.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/api-gateway-ci-pipeline.yml/badge.svg"&gt;&lt;img src="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/api-gateway-ci-pipeline.yml/badge.svg" alt="CI — API Gateway"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/movie-service-ci-pipeline.yml/badge.svg"&gt;&lt;img src="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/movie-service-ci-pipeline.yml/badge.svg" alt="CI — Movie Service"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/reservation-service-ci-pipeline.yml/badge.svg"&gt;&lt;img src="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/reservation-service-ci-pipeline.yml/badge.svg" alt="CI — Reservation Service"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/identity-service-ci-pipeline.yml/badge.svg"&gt;&lt;img src="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/identity-service-ci-pipeline.yml/badge.svg" alt="CI — Identity Service"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Architectural Overview&lt;/h2&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Diagram&lt;/h3&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/docs/system-architecture-diagram.png"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fmazenaly256%2FCinema-Seat-Reservation-System%2FHEAD%2Fdocs%2Fsystem-architecture-diagram.png" alt="System Architecture Diagram"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Services&lt;/h3&gt;

&lt;/div&gt;
&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Service&lt;/th&gt;
&lt;th&gt;Responsibility&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;API Gateway&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Centralized authentication, rate limiting, request timeouts, and routing to the main services&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Identity Service&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Centralized Identity Provider — user management and JWT issuance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Movie Service&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Movies and showtimes management&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Reservation Service&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Seat layout, seat holds, and seat reservations&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Getting Started&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;The system is live and ready to test via &lt;strong&gt;&lt;a href="https://www.postman.com/mazenaly256-3830648/workspace/cinema-seat-reservation-system-api-documentation" rel="nofollow noopener noreferrer"&gt;Postman Workspace&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The workspace includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Complete API documentation, with organized request collections and folders for each service&lt;/li&gt;
&lt;li&gt;All API endpoints with example requests and responses, featuring interactive testing&lt;/li&gt;
&lt;li&gt;Pre-configured variables containing hosting Azure VM IP with ports to access the services&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How to…&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/h2&gt;

&lt;h2&gt;
  
  
  Problems
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Latency Problem
&lt;/h3&gt;

&lt;p&gt;One of the bottlenecks that appeared through load-testing, is that the latency of a specific endpoint (Get all showtimes with filters) takes the latency was around 850ms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Availability Problem
&lt;/h3&gt;

&lt;p&gt;Availability is simply the ability of the system to be alive and respond to requests, and do not completely die.&lt;/p&gt;

&lt;p&gt;Another problem appeared when I tried to stress test the system, I simulated huge traffic on the system and it was across the critical path in the system (that is the longest trip for a request across the services).&lt;br&gt;
Due to the large traffic the service took long time to respond, and also under stress testing the service crashed, due to exceeding the memory that limit that I determined for the container.&lt;/p&gt;

&lt;h2&gt;
  
  
  Furthermore, from a user experience perspective, a service that returns a quick, graceful error is far better than one that hangs indefinitely. Under stress testing, &lt;strong&gt;the P95 latency reached a painful 16 seconds&lt;/strong&gt;, a frustrating experience where users are highly likely to lose patience and abandon their requests entirely.
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Decisions To Solve The Problems
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Solution of Latency Problem
&lt;/h3&gt;

&lt;p&gt;I accepted the idea that the latency has to be slightly high, due to the network overhead that caused by having the database and service running on different servers in different countries so there is a long trip for data over the network between the service and database, but the 850ms latency is also very high even if we consider the network delay, there must be a problem with my system design.&lt;/p&gt;

&lt;p&gt;At first glance, since the problem was related to database reading operations (data retrieval), then database indexing and caching are obvious answers to improve performance and reduce latency, but guess what? Neither of them was the solution in my case.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why indexing did not reduce the latency:
&lt;/h4&gt;

&lt;p&gt;Generally, indexing is a go-to solution in cases like this and I already created a database index on the table, but guess what? There was not any reduction in latency.&lt;br&gt;
What I learned is that due to the high latency, and the  relatively small number of rows (which is ~10,000 rows), the impact of indexing on the latency is invisible especially since the network delay itself was already massive.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why caching is not a solution (common problems in both distributed and in memory):
&lt;/h4&gt;

&lt;p&gt;Actually, I found caching would make things much worse, there are many cons for caching my situation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Range-based queries (from and to date filters) produce highly variable cache keys as if data of 2 days is requested then data of five days that span those two days is requested again, then actually we absolutely need to hit database again as we do not know if there are showtimes in those excess 3 days or not, cache usage rate would be low.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Also full-list caching becomes impractical as the dataset grows to 100k+ rows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cache invalidation on create/update/delete for the domain resources adds complexity that it actually does not pay off.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those are problems in both in-memory and distributed caching, but even each one has specific cons.&lt;/p&gt;

&lt;p&gt;the main problem with the in-memory caching is in a multi-containered deployment, each container instance maintains its own isolated cache, this produces inconsistent responses, as each container will have its own data separately — unacceptable for a booking system. Furthermore, syncing all those data will add significant complexity.&lt;/p&gt;

&lt;p&gt;also in my case distributed caching (via Redis or any similar) will introduce its own network overhead to transfer data between the service and the Redis instance, that introduce more network delay that will increase latency.&lt;/p&gt;

&lt;h4&gt;
  
  
  The real solution, eliminating unbounded query results
&lt;/h4&gt;

&lt;p&gt;It is pagination, instead of retrieving huge number of rows for a single request, return only a few number of rows like 10 or 20. Practically speaking, users never need more than them, they will see them and if they need more, they can load more and in this case they will accept waiting a few additional milliseconds to see new 10 or 20 showtimes, instead of waiting 850ms to retrieve 10,000 rows that user will never consider them all. &lt;strong&gt;This solution improved the performance reducing the P95 latency to ~515ms, and increased the throughput (the handled traffic) by ~25%&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Theoretically, there is an issue here that may require changing the pagination technique, the issue is that the database still reads every row it skips. Page 5 is fast. Page 5000 is slow. This becomes visible only when the number of becomes really huge.&lt;br&gt;
However, practically speaking, this number of rows will not requested as it require very long date window that contains this enormous number of showtimes, that is not requested in the real life.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution of the availability problem
&lt;/h3&gt;

&lt;p&gt;To solve this I applied rate limiting on the API gateway, this ensures that any traffic exceeding or limit fails at the edge, guaranteeing that only a manageable number of requests are processed within a given time window.&lt;/p&gt;

&lt;p&gt;Additionally, applying request timeouts helped as it prevented misbehaving requests that are unusually slow for some specific reason from degrading all the system as they take long time to be processed and take some resources. Now the system automatically cancels any request after 8 seconds and disconnect all the related connections and frees up all its allocated resources to be available to another incoming request to consume.&lt;/p&gt;

&lt;p&gt;And prevented the latency from exceeding 8 seconds.&lt;/p&gt;




&lt;h2&gt;
  
  
  Possible Areas of Improvement
&lt;/h2&gt;

&lt;p&gt;In this section I would like to say that honestly, I do not know if these features will actually improve the system, or their effect will be minimal. For sure they will come with their overhead and trade-offs and will require a decision to determine whether they will introduce &lt;em&gt;an actual improvement&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Caching
&lt;/h3&gt;

&lt;p&gt;I discussed the caching when addressing the latency problem and I mentioned why it did not work, but caching may be useful in another part in the system specially when service is read heavy, and also with data that do not change frequently or the data that the way of querying them is consistent (that was not the case in my problem above).&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Event-Driven Architecture and Message Brokers like Kafka and RabbitMQ
&lt;/h3&gt;

&lt;p&gt;At first glance, this solution clearly introduces a major architectural trade-off: &lt;strong&gt;Database Replication&lt;/strong&gt;. On the other hand, it has benefits including that no inter-service network calls are required so the system will be faster, and also no cascading failures, suppose that movie service crashed, the reservation service has all data on its database replica and can actually use and do its work (reserving seats in showtimes) without even knowing that movie service is down.&lt;br&gt;
This will reduce the synchronous HTTP calls that happen frequently between the services in cases like checking movie when adding a new showtime, or checking showtime when trying to reserve a seat. All those are synchronous calls that enforce the upstream service (service that makes a call) to wait for the downstream service (the called service) to respond. Also upstream service fails to do its job if the downstream service goes down.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Change the database location
&lt;/h3&gt;

&lt;p&gt;There are two options to achieve this.&lt;br&gt;
Option A: is to just get a nearer the server for our database. There is no architectural side effects and never presents more challenges, just host the DB on a nearer server to the deployment server of the services, this reduces the travelling distance for data thereby reduce network overhead.&lt;/p&gt;

&lt;p&gt;Option B: is hosting the database on the same machine as the services, this will be actually better in terms of performance due to eliminating the network overhead. But it will introduce its own overhead like the configuration headache and managing the DBMS on the server.&lt;br&gt;
Additionally, it comes with a trade-off, which is &lt;strong&gt;coupling the downtime of DB with the downtime of the system.&lt;/strong&gt; When the services and the database are hosted on different servers, the services can still be available and return friendly errors when the DB server can not be reached, instead of being fully down if they all are on one machine. This is a violation for the principle of &lt;em&gt;single point of failure&lt;/em&gt;, that is "eliminating cascading failures by separating concerns across different machines", but as I said above ad want you to remember: &lt;em&gt;System design is all about Trade-offs&lt;/em&gt;.&lt;/p&gt;

</description>
      <category>redis</category>
      <category>testing</category>
      <category>architecture</category>
      <category>database</category>
    </item>
    <item>
      <title>Cinema Seat Reservation System — Part 2: Transitioning To Production-Scale and Deploying on Azure Cloud</title>
      <dc:creator>Mazen Aly Abdelfattah</dc:creator>
      <pubDate>Wed, 24 Jun 2026 06:26:12 +0000</pubDate>
      <link>https://dev.to/mazen-13/cinema-seat-reservation-system-from-baseline-local-development-to-live-cloud-native-production--238k</link>
      <guid>https://dev.to/mazen-13/cinema-seat-reservation-system-from-baseline-local-development-to-live-cloud-native-production--238k</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This is the second part of sharing my journey to create a microservices-based backend system, in the previous part, I introduced the system and its services.&lt;br&gt;
In this part I am going to mention the main things that happened with me from then until now.&lt;/p&gt;




&lt;h2&gt;
  
  
  Transitioning to online DBaaS platforms
&lt;/h2&gt;

&lt;p&gt;The first main thing was to transition my databases from my local device to accessible over the internet. I used &lt;strong&gt;Neon&lt;/strong&gt; and &lt;strong&gt;MongoDB Atlas&lt;/strong&gt;. Although performance-wise it is better to deploy the database on the same server that the whole system so all services can access the databases without &lt;strong&gt;network overhead&lt;/strong&gt;, This solution is better from a point, that is avoiding consuming the free VM instance that I got to host my main services, as with DBaaS platforms I will not require storage for databases or additional overhead to handle the DBMS on a free small resources-constrained VM.&lt;/p&gt;




&lt;h2&gt;
  
  
  Observability
&lt;/h2&gt;

&lt;p&gt;Observability is one of the main concerns in any system, it gives the ability for the system to expose what happens inside it without any need to guess and manually trace the code to determine where the error may happened.&lt;br&gt;
I utilized &lt;strong&gt;OpenTelemetry&lt;/strong&gt;, as I found it is most used and accepted tool to log, trace and collect metrics about the system and the traffic. Also, I loved that it is not related to specific framework, that is .NET by the way, I loved the idea that it is standalone tool.&lt;br&gt;
But logging and tracing and metrics collection will not be beneficial if we do not see it actually and can achieve &lt;strong&gt;monitoring&lt;/strong&gt; from those telemetry data, so I used &lt;strong&gt;Grafana Cloud&lt;/strong&gt; to export the telemetry data to some place that is accessible online and a tool that can generate dashboards and visualizing for the metrics (&lt;strong&gt;Prometheus&lt;/strong&gt;), and UI that can show all the telemetry data easily.&lt;/p&gt;




&lt;h2&gt;
  
  
  Resilience
&lt;/h2&gt;

&lt;p&gt;I achieved &lt;em&gt;resilience&lt;/em&gt; in this system, by implementing Retry and Circuit-Breaker Pattern, that applies retires and mitigates the effect transient failures, so user can not know that there is actually a failure happened.&lt;br&gt;
Without it, any HTTP transient failure when calling a downstream service will lead to Internal Server Error response directly, even there is no permanent failure in the downstream service.&lt;/p&gt;




&lt;h2&gt;
  
  
  Deployment
&lt;/h2&gt;

&lt;p&gt;Until this point, we have a system that is fully functional and have consistent docker configuration for its services via Docker Compose, and it database is already there and available.&lt;/p&gt;

&lt;p&gt;Now this is the point at which I wanted my system to be online and accessible from everywhere over the world, and really reach the goal: From Baseline Local Development &lt;strong&gt;To Live Cloud-Native Production&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For this I chose Azure Cloud Services, I had a virtual machine on Azure Cloud and installed Docker on it, also I configured the firewall so it added two ports to access my system, one for Identity Service, and the another one is for API Gateway.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I did is as follows:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;I created images from my actual code on my local machine, and pushed it to GitHub Container Registry.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I issued a token from GitHub to allow Docker engine that is installed on the virtual machine to actually pull and push the images (it is called Packages of type containers on GitHub) from and to my GitHub account.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I copied (via SCP) Docker Compose file with secret env variables file, from my local machine to the online Azure VM. Now the VM has Docker engine, and the ability to access any uploaded images on GitHub and pull/download them on the VM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, I executed the command: &lt;code&gt;docker compose pull&lt;/code&gt; to pull images from GitHub Container Registry then &lt;code&gt;docker compose up&lt;/code&gt;  and to spin up the containers from them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Voilà! the system became live and accessible online.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And now, we have a live production-scale cloud-native application.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/releases/tag/v4.0.0" rel="noopener noreferrer"&gt;See GitHub Release, Capturing Project at This Point&lt;/a&gt;
&lt;/h3&gt;




&lt;h2&gt;
  
  
  Workflow
&lt;/h2&gt;

&lt;p&gt;After I had this whole setup, my workflow became very consistent, it is as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Make a change in the code, fixing a bug or enhance codebase or add a feature, then push it to GitHub, every change should be pushed to GitHub to achieve CI (continuous integration) practice in software development, that is simply the practice of merging the new code changes to the branch and then get automatically tested and checked, and this is achieved by the &lt;strong&gt;CI Pipeline&lt;/strong&gt; that I built using &lt;strong&gt;GitHub Actions&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then I directly rebuild the images so I get the latest changes on the code reflected on the new images.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I push these latest versions of images to GitHub Online Registry.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I access the VM through SSH, delete the old &lt;code&gt;docker-compose.yml&lt;/code&gt; and &lt;code&gt;.env&lt;/code&gt; files if they are modified.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rerun the docker compose commands to pull the latest images from GitHub Container Registry and spin up new containers and delete the old containers. So, CD (Continuous Deployment/Delivery) is achieved here (manual CD workflow).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




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

&lt;p&gt;In conclusion, I want to say that this project made me learn many valuable skills, concepts and tools. There are many another things that not mentioned to keep things brief (you can get some of them by taking a look on GitHub Repository that is mentioned in Part 1 from this series, and view the commits history), and focus on the points that I feel that it really matters and think that readers can learn from it.&lt;/p&gt;

&lt;p&gt;Take a look on this series title, we really transitioned from &lt;em&gt;"Baseline Local Development"&lt;/em&gt; that is the MVP that runs on my machine, to &lt;em&gt;"Live Cloud-Native Production"&lt;/em&gt; that actually appeared in observability setup and deploying on Cloud and making it accessible online.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;If you have questions or feedback, drop them in the comments. I hope I can learn from or add benefit to one of you&lt;/u&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;For now, I am testing the system to determine its bottlenecks, for sure it has many areas of improvement, and things that even can be added to this project to make it better and more performant, I am going to mention some bugs and issues that faced me and how I overcame it and learned from them and some decisions that I made in the system. This what I will mention in the next part "Bugs, Decisions and Areas Of Improvement".&lt;/p&gt;

</description>
      <category>cloud</category>
      <category>azure</category>
      <category>distributedsystems</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Cinema Seat Reservation System — Part 1: Overview &amp; Architecture</title>
      <dc:creator>Mazen Aly Abdelfattah</dc:creator>
      <pubDate>Tue, 26 May 2026 08:11:09 +0000</pubDate>
      <link>https://dev.to/mazen-13/cinema-seat-reservation-system-from-baseline-local-development-to-live-cloud-native-production--1d9i</link>
      <guid>https://dev.to/mazen-13/cinema-seat-reservation-system-from-baseline-local-development-to-live-cloud-native-production--1d9i</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I am writing this series of blog posts to document what I am learning while building a project. You are welcome to criticize and guide me toward areas of improvement — or maybe, and I genuinely hope this, I can introduce you to concepts or ideas you haven’t encountered before, so we both can grow. I will focus on architectural and design concepts and the technologies that can be applied regardless of your framework and programming language of developing the application.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  GitHub Repository
&lt;/h3&gt;

&lt;p&gt;There you can find more details, including ADRs (Architectural Design Records) and more extensive documentation.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/mazenaly256" rel="noopener noreferrer"&gt;
        mazenaly256
      &lt;/a&gt; / &lt;a href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System" rel="noopener noreferrer"&gt;
        Cinema-Seat-Reservation-System
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Cloud-native microservices-based cinema seat reservation system developed. Designed for modularity and scalability.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Cinema Seat Reservation System&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;A cloud-native, microservices-based ecosystem developed in ASP.NET Core with REST APIs. This system features deliberate design decisions optimized for modularity, scalability and resilience — implementing proven distributed systems patterns such as Retries and Circuit Breakers and Request Timeouts alongside automated CI pipelines and manual deployment workflow.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/api-gateway-ci-pipeline.yml/badge.svg"&gt;&lt;img src="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/api-gateway-ci-pipeline.yml/badge.svg" alt="CI — API Gateway"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/movie-service-ci-pipeline.yml/badge.svg"&gt;&lt;img src="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/movie-service-ci-pipeline.yml/badge.svg" alt="CI — Movie Service"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/reservation-service-ci-pipeline.yml/badge.svg"&gt;&lt;img src="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/reservation-service-ci-pipeline.yml/badge.svg" alt="CI — Reservation Service"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/identity-service-ci-pipeline.yml/badge.svg"&gt;&lt;img src="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/actions/workflows/identity-service-ci-pipeline.yml/badge.svg" alt="CI — Identity Service"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Architectural Overview&lt;/h2&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Diagram&lt;/h3&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/docs/system-architecture-diagram.png"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fmazenaly256%2FCinema-Seat-Reservation-System%2FHEAD%2Fdocs%2Fsystem-architecture-diagram.png" alt="System Architecture Diagram"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Services&lt;/h3&gt;

&lt;/div&gt;
&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Service&lt;/th&gt;
&lt;th&gt;Responsibility&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;API Gateway&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Centralized authentication, rate limiting, request timeouts, and routing to the main services&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Identity Service&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Centralized Identity Provider — user management and JWT issuance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Movie Service&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Movies and showtimes management&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Reservation Service&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Seat layout, seat holds, and seat reservations&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Getting Started&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;The system is live and ready to test via &lt;strong&gt;&lt;a href="https://www.postman.com/mazenaly256-3830648/workspace/cinema-seat-reservation-system-api-documentation" rel="nofollow noopener noreferrer"&gt;Postman Workspace&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The workspace includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Complete API documentation, with organized request collections and folders for each service&lt;/li&gt;
&lt;li&gt;All API endpoints with example requests and responses, featuring interactive testing&lt;/li&gt;
&lt;li&gt;Pre-configured variables containing hosting Azure VM IP with ports to access the services&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How to…&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;





&lt;h2&gt;
  
  
  System Overview
&lt;/h2&gt;

&lt;p&gt;I have built a &lt;strong&gt;microservices-based&lt;/strong&gt; backend system, for handling seat reservations in a cinema, each service has its &lt;strong&gt;own database&lt;/strong&gt;. I applied many new concepts that I have learned including how to split the system and build the architecture that offers the modularity and future scalability for the application, building and securing API endpoints using JWT, implementing an &lt;strong&gt;API gateway&lt;/strong&gt; to be the single entry point for my whole system, &lt;strong&gt;building a basic CI Pipeline using GitHub Actions&lt;/strong&gt;, containerizing the services with configuring and running together via &lt;strong&gt;Docker Compose&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  Services
&lt;/h3&gt;

&lt;p&gt;&lt;u&gt;Movie Service:&lt;/u&gt; Responsible for CRUD operations on movies and showtimes, and enforces role-based access control.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Reservation Service:&lt;/u&gt; Responsible for handling seats availability checks and the logic of seats reservations and payment.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Identity Service:&lt;/u&gt; Acts as the &lt;strong&gt;centralized Identity Provider&lt;/strong&gt; for the whole system, responsible for &lt;strong&gt;storing and managing users&lt;/strong&gt; and &lt;strong&gt;issuing JWT tokens&lt;/strong&gt; that are trusted across all the system.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;API Gateway:&lt;/u&gt; The single entry point for the system, acting as an &lt;strong&gt;architectural AOP (Aspect-Oriented Programming) layer&lt;/strong&gt;. It &lt;strong&gt;centralizes cross-cutting concerns&lt;/strong&gt; like authentication, rate limiting, and request timeouts in one place instead of duplicating their logic across all the system services. In addition to the main responsibility of API Gateway that is &lt;strong&gt;forwarding the requests to downstream services&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  System Architecture
&lt;/h3&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%2F4j4liw4f8axc0chel2mg.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%2F4j4liw4f8axc0chel2mg.png" alt="Basic System Architecture Diagram" width="800" height="604"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://github.com/mazenaly256/Cinema-Seat-Reservation-System/releases/tag/v3.0.0" rel="noopener noreferrer"&gt;GitHub Release&lt;/a&gt;
&lt;/h3&gt;




&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;What I am going to do in my next few posts, is to document the main points of transitioning this system from the &lt;strong&gt;development phase on my local machine&lt;/strong&gt; to a &lt;strong&gt;fully deployed, cloud-native, production-scale system&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>architecture</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
