<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sajaclvishkai on Medium]]></title>
        <description><![CDATA[Stories by Sajaclvishkai on Medium]]></description>
        <link>https://medium.com/@sajaclvishkai?source=rss-d710a5a1964a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*YADMkf63mQyCWv8t</url>
            <title>Stories by Sajaclvishkai on Medium</title>
            <link>https://medium.com/@sajaclvishkai?source=rss-d710a5a1964a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 12:17:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sajaclvishkai/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How we handled large data at Embargo]]></title>
            <link>https://medium.com/@sajaclvishkai/how-we-handled-large-data-at-embargo-f03a282bb5cf?source=rss-d710a5a1964a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f03a282bb5cf</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Sajaclvishkai]]></dc:creator>
            <pubDate>Thu, 22 May 2025 14:11:31 GMT</pubDate>
            <atom:updated>2025-05-22T15:59:02.576Z</atom:updated>
            <content:encoded><![CDATA[<p>Dear reader,</p><p>As a junior tech writer, I would like to start the article about who is the writer.<br>My name is Sajad,<br>I’ve been working with computers for a long time now!<br>I’ve started with game development; and 15 years later, I’m still trying to recreate the amount of fun =)<br>For the past year, at <strong>Embargo</strong>, I had the honor to work with a group of talented people, as their iOS lead (Basically learning from them and pretending that I knew it all).</p><h4>What is Embargo?</h4><p>TL;DR Embargo is a loyalty system, we offer the whole eco-system for loyalty systems, from user end applications, to restaurant management applications, CRM, online ordering, charts, internal applications, AI, etc…</p><p>In the heart of this business, is data; it can be fetching, persisting, or preparing data for needed interactions…<br>As you already guessed, we have to deal with a huge amount of data, and we have to do it lightening fast!</p><p>But software being software, some times the amount of data that has to be dealt with, exceeds the the lightening speed.<br>In this article, I will not dive into every module, but I’m aiming to unroll how we did it for a few module, the decisions, and hopefully it should give you enough information to tackle your next project to get a better decision.</p><h4>Who is this article for?</h4><p>Since I’m an iOS Engineer, I am speaking from mobile development perspective, and the design decisions would be only focused on the mobile side; but this article should be for every tech enthusiast.<br><strong>One thing to mention is, it’s definitely not a road map to how do it, bare that in mind please.</strong></p><h4>Lab:</h4><p>I will run everything on:<br>- iPhone 12<br>- iOS 16.4<br>- Environment will be artificial to a common user (Such as internet connectivity, storage, etc…)</p><h4>First of all, I would like to shine light on some common sense questions:</h4><p>1. How much data is considered large?<br> I’ve talked about huge amount of data, but how much data is considered huge?<br>This question does not have one factor, it’s actually a decoy question.<br>It’s a question of resources!<br>When you are working with a pentium computer, even a few gigabytes can be considered nothing, having <strong>enough time</strong> to process it! <br>Exactly, the other `hidden` equation is time!<br>In favour of shining some lights (and not creating more questions), I will avoid using magical numbers, and stick to what we dealt with, the actual amount.<br>If we take any user, and only focus on the client app, we end up with around a gigabyte (~1.24) of data that is only unique to that user.</p><p>2. We are talking only about client application (Embargo Wallet).<br>3. The articles focuses only on the runtime aspect of the application.<br>4. Codebase decisions and team related questions has not been addressed, but they really are a great factor for the design decisions, unfortunately at this point, I am skipping some parts and leaving hints to figure out why we decided to move as like we did.<br>5. For the past year, I had the honour to create refactoring road maps, first, we migrated to Swift concurrency, and then we switched the gui library to SwiftUI.</p><h4>Application environment:</h4><p>The application consist of ~20 modules at the moment, I will try to shortly address the bare-bone of it, and a little historical decisions about it.</p><h4>1. Storage</h4><p>At the early stages of the application, this application was built relaying only on a relation data base, SQL.<br>At the later stages, it was decided to move to a non-relational db, CoreData.<br>As the software grows, the decision at the moment is to use them both.<br>As you already guessed some data needs the relation representation, and some does not need.<br>We migrated to use a relational one (SQL), and a non-relation one (Realm)(and a separate storage for image cache) to meet with our needs.</p><h4>2. Connectivity</h4><p>At the early stages everything was built around Alamofire, later on we have developed our own library on top of URLSession, since that library was heavily depending on Operations, we moved away from it by bypassing the closure executors at the first stages, and then through time we built the same library using Swift concurrency.<br>As you already guessed, we are using REST for our apis, and strangely we are using the standard protocol and standard configuration that URLSession gives us (vary on the iOS version but mostly using HTTP/2).<br>Until this stage of the application, one-way connection was meeting our needs, but as we grew, we saw the application to use bidirectional connection.<br>Hence, at the exact moment of this article, we are developing our own bidirectional connection using tcp.</p><h4>3. GUI</h4><p>You were expecting me to say at the early stages, right? =D<br>The first iteration was built with storyboards, but as the team grew, the decision was made to make re-make modules step by step without using storyboards or xib files,<br>We successfully migrated everything, and I mean everything to be created in code.<br>For the past year, we learned, cried, and finally found our way how to use SwiftUI as our main gui library.<br>But some parts has been remained untouched in UIKit.<br>But the plan is to move away from UIKit (If possible) and this has been persuade by teams themselves! (Which is really nice tbh)</p><h4>4. Logging/Analytics</h4><p>Over the years, we have tried multiple libraries and dependencies, even created our own,<br>And in this article it should not be a matter how the analytics system works in our code, but related to the log; I would like to explain how the system works.<br>Working in the hospitality and loyalty sector requires a logging system that is efficient, purposefully structured for debugging, and is highly secure. <br>Clear and intentional log design is essential to ensure reliable monitoring and traceability without compromising sensitive data.</p><p>Hence, we created a multiplex logging system, that uses file, internet and standard output (on debug builds).</p><h4>5. Modular structure</h4><p>Since every mvp starts with the bare minimum, and then later builds on top of that, we were no different.<br>Historically, we refactored from a monolithic, unified mvc like structure, to a monolithic everything in viper!<br>As the team grew, we moved away from having a monolithic codebase to a modular approach, with full flexibility for each team to chose their own way.<br>This change needed a huge shift in our dependency system as well.<br>So we incrementally pushed the modules and our the dependencies to accept hexagonal architecture (Which is still a work in progress).<br>Extra: Choosing this, enabled us to move our build system to Bazel in a more efficient way.</p><p>Alright, lets start with the boring part :-)<br>As you should have a good view of Embargo by now, I would like to start with one of our biggest modules; <strong>Authentication</strong>.</p><h4>Authentication:</h4><p>This is one of the modules that has the most effect on our intro.<br>A user at most, I repeat, at most, gives ~3 seconds to any application to load, after that, it’s either a negative impact, or getting closed.<br>If we take the user log-in process as an example: we actually have less than 3 seconds to fetch the needed data from multiple end points, process it, and store it.<br>That being said, if the application is fresh, thats when we need to fetch the whole related data (the giga byte that I have mentioned),<br>And having around a giga byte on our hands, it makes it super tense to handle it fast.<br>- The first factor is internet; to download a gigabyte, it really is time and resource consuming!<br>So breaking it to separate calls is the first logical thing to do.<br>Breaking it and to multiple calls concurrently; after breaking it, we still have the giga byte, but on separate calls, which will make things worse in resource perspective!<br>Having multiple heavy io’s will only make this more burden; if we don’t optimise it further.<br>Assuming we maxed out the hardware utilization, the first thing that we did, we have break the data, the actual data, based on some algorithms like using geo ip, time of the day and etc…<br>But still there are a lot at stake,<br>Even ~20mg of data takes around a second!<br>After careful consideration of how to make the most out of our network calls, we were still using ~10 seconds to prepare everything!<br>In R&amp;D stage, we realised that one of the most time consuming parts of our application is parsing the jsons.<br>Using `<a href="https://developer.apple.com/documentation/foundation/jsondecoder">JSONDecoder</a>` as our main decoder faded away as fast as we decided that we need to optimize this part, and it gave its place to a state of the art library named `<a href="https://github.com/simdjson/simdjson">simdjson</a>`.<br>With utilizing `<a href="https://en.wikipedia.org/wiki/Single_instruction,_multiple_data">SIMD</a>` instructions, our login/preparation time came down to ~4 seconds, which is like a miracle at this point!<br>It actually made us some room to remove the geo-ip location logic.</p><p>- The second factor is db writes.<br>Our strategy has always been offline first, and we intended to keep as is.<br>Having to write the whole user/app data as we are preparing the the views and the logics are just unjustified.<br>So offloading the work would be the right choice, offloading the work not to another thread, in time!<br>Doing so, heavily changes the system, (arguably) for good!<br>- Suddenly the system needs to be more fault tolerant, as if it crashes the whole procedure that we did is lost.<br>- The system needs to be more reliable, reliable in terms of being aware of active tasks/background tasks and resource usage.<br>- System really needs to handle cache and repositories in an performance efficient manner.<br>- And in some scenarios the system really needs to know when to initiate the write tasks, and this brings more coupling in internal structures/services.</p><p>With utilizing an algorithm to do so, we managed to bring the the loading time under 3 seconds! \:D/</p><h4>Landing Module:</h4><p>As the user returns to the application, most of the related information to the user, to venues, online ordering, etc needs to be updated.<br>Doing so, again we are the same track as our login.<br>So it’s only logical to use some kind of logic to fetch the data that is needed, but what is really needed, how we can communicate what we need in this state?<br>Basically we need to fetch a diff from the data since we last talked to the server (what has been updated, removed, or added).<br><strong>A quick word, </strong>Why we didn’t use GraphQL/Protobuf?<br>Well, this has a long answer, but the gist of it is, we think our api’s has been matured enough through time to mimic the gain of using another protocol.<br>We might end up doing so in future, but I don’t see that happening anytime soon.<br>Back to the landing, for obvious reasons, we needed to communicate what is the last row/item that we have received for the call (e.g venue), and specifically a timestamp of when we got that entity information.<br>A time-based pagination!<br>Doing so, we need to store extra information related to every row of entity, and sending it to server, we also need to do extra work related to change a simple get request and add the `utimestamp` (Update timestamp).<br>But in doing so, we get a huge benefit of performance.<br>For you who are interested where the diff is happening, it’s servers job.<br>But maybe the next article would be related to this part, it’s a super heavy operation, also a quite enjoyable problem to solve :)</p><h4>Conclusion</h4><p>Handling large-scale data efficiently on mobile devices is not just a technical challenge; it’s a necessity when working in a fast-paced, user-first environment.<br>As we navigated through legacy decisions, architectural shifts, and performance bottlenecks, one thing became clear: speed, stability, and thoughtful trade-offs are non-negotiable when user expectations are measured in seconds.</p><p>This article barely scratches the surface of what it means to balance data heavy systems with delightful UX in a mobile-first world.<br>I hope it gave you some insight into our journey and the pragmatic choices that led to meaningful improvements.<br>Whether you’re facing similar constraints or planning ahead for scale, remember: performance is not just about code! it’s about timing, intention, and resilience.</p><p>Thank you for reading,<br>Sajad Vishkai</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f03a282bb5cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>