<?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: Innocontents Vitcord S.L.</title>
    <description>The latest articles on DEV Community by Innocontents Vitcord S.L. (@vitcord).</description>
    <link>https://dev.to/vitcord</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F945%2Fa22afa61-aa44-45da-8021-9e988843015a.jpg</url>
      <title>DEV Community: Innocontents Vitcord S.L.</title>
      <link>https://dev.to/vitcord</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vitcord"/>
    <language>en</language>
    <item>
      <title>Web API architecture for millenials</title>
      <dc:creator>Miguel Coleto</dc:creator>
      <pubDate>Fri, 26 Jul 2019 06:29:39 +0000</pubDate>
      <link>https://dev.to/vitcord/web-api-architecture-for-millenials-2n9</link>
      <guid>https://dev.to/vitcord/web-api-architecture-for-millenials-2n9</guid>
      <description>&lt;p&gt;At Vitcord we always try to offer the best experience for our users. &lt;a href="https://dev.to/vitcord/tearing-vitcord-backend-46m8"&gt;Recently, we discovered that push notifications management was starting to cause a bottleneck&lt;/a&gt; in our monolith so we decided to face this problem before it would become worse.&lt;/p&gt;

&lt;p&gt;At the moment we started to study the solution for this challenge, push notifications weren’t a big part of our monolith, so we realized that extracting it to an isolated microservice could be a good idea. Besides, push notifications become a key of success in terms of retention once you have an interesting user base. Extracting this responsibility from our main server means we can scale this part separately and give it a better maintenance too.&lt;/p&gt;

&lt;p&gt;Once we decided what we were building we started to think about how we were going to do it. From the beginning, we knew that our database should be Cassandra or DynamoDB, as notifications and messaging are the kind of feature this databases are built for. Choosing the language and framework did take us a little bit longer, but in the end we went for Kotlin and Spring Boot. These two make a perfect couple and some of our tech guys had some experience with Kotlin, besides, the Android team has their app completely in this language.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing the right architecture
&lt;/h2&gt;

&lt;p&gt;When we started designing the system we knew that it wouldn’t have a lot of actions (one for each type of push notification basically), but they could be more in the future. We knew that a vertical oriented approach suited perfectly as it allows to distribute the work easily, plug in or out actions and maintain each vertical separately without touching more code than needed.&lt;/p&gt;

&lt;p&gt;After some research we discovered an architectural pattern that fitted our design really well: Action Domain Responder. This pattern was born as an evolution for the classic Model View Controller.&lt;/p&gt;

&lt;p&gt;MVC is an architectural pattern for apps with user interfaces born in the 90s. The Controller maintains a state of the program which tells the View how it should be showed to the user. With each change to the state the UI should render automatically. It became very popular in backend thanks to frameworks like Ruby on Rails, which follow this pattern for web applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AP9aPAwygaZVfEq5x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AP9aPAwygaZVfEq5x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A better MVC for the Web
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://pmjones.io/adr/?source=post_page---------------------------" rel="noopener noreferrer"&gt;Action Domain Responder&lt;/a&gt; was created in 2014 as a refinement for MVC in the context of web REST APIs. One key principle of REST is that is stateless and each HTTP request is treated independently, so there is no state to keep. ADR proposes a much more natural flow for backend applications:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The Action receives an HTTP request. It collects any required input and calls the Domain with them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Domain manipulates the information and applies any business logic. It returns a result to the Action.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Action calls the Responder with the result of the Domain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Responder builds an HTTP response and sends it.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F528%2F0%2Aw0L6jYVaNl2bZPXT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F528%2F0%2Aw0L6jYVaNl2bZPXT.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ADR suits our vertical oriented approach because we can fulfill SOLID’s Single Responsibility Principle to the max:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In ADR each Action is a separate class with only one method instead of a Controller with one method for each endpoint. Actions only connect Domain with Responders.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can model the Domain following a Command pattern which helps us to isolate the business logic and reuse it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Responders only job is to build HTTP responses based on an input. They can be pure functions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every vertical is a set of an Action, a Responder and a Command. This allows us to add or remove them without affecting more components than these. Testing also becomes easy peasy as every piece has a limited responsibility and they usually have one or two methods. Structure is also another plus as it is really easy to find every file by their corresponding Action, and you can tell every feature of the app from a top level look of the Actions.&lt;/p&gt;

&lt;h2&gt;
  
  
   Theory is good but... show me the code!
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AshKoi9dvAF1SWwOR" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AshKoi9dvAF1SWwOR"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Actions&lt;/strong&gt; define the endpoint they are listening to and only have one &lt;em&gt;execute()&lt;/em&gt; method that will be invoked with each request. They call the Domain with the request input, then they call the Responder with the result and lastly they return the response that the Responder built.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AugAtM6txZN8zCJPx" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2AugAtM6txZN8zCJPx"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Domain&lt;/strong&gt; is divided in classes following the Command or Use Case pattern. They are in charge of manipulating the data, storing them in database, publishing domain events, etc. As the Actions, they always have one &lt;em&gt;invoke()&lt;/em&gt; method which returns an Either datatype from &lt;a href="https://arrow-kt.io/?source=post_page---------------------------" rel="noopener noreferrer"&gt;Arrow&lt;/a&gt;, the library for functional programming in Kotlin.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Either&lt;/strong&gt; represents some operation which can fail or succeed. It works like a black box in which we operate, but we won’t know if everything went okay or not until we open it. This is by far better than throwing exceptions because we are telling explicitly that our code can fail and we force ourselves to handle every path.&lt;/p&gt;

&lt;p&gt;In this specific case we are telling that this command can return a Notification if everything went right or it can return an Error from the &lt;strong&gt;Algebraic Data Type (ADT)&lt;/strong&gt; we created (&lt;em&gt;Errors&lt;/em&gt;), this means the error must be one of the objects under the sealed hierarchy of the parent class.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2An2yALTMJFf1svd2c" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F700%2F0%2An2yALTMJFf1svd2c"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Responders&lt;/strong&gt; just need to open the Either box and create a HTTP response based on its content. For this purpose we have the &lt;em&gt;fold()&lt;/em&gt; method which accepts two lambdas and executes one or the other, depending if the content is an error or a success.&lt;/p&gt;

&lt;p&gt;Modelling the errors in an ADT style forces us to handle every case thanks to Kotlin’s &lt;em&gt;when&lt;/em&gt;. If I added another error to the hierarchy, the Responder wouldn’t compile until I handled it in the &lt;em&gt;when&lt;/em&gt; block.&lt;/p&gt;

&lt;h2&gt;
  
  
  In conclusion
&lt;/h2&gt;

&lt;p&gt;We think ADR is a better architectural pattern for REST APIs than MVC and it fits our development workflow really well. It has allowed us to deploy this project in little time and it will be easy to maintain thanks to the responsibility separation, testability and good structure the architecture is giving us.&lt;/p&gt;

&lt;p&gt;Thank you for reading this post. Please, give us feedback by commenting or &lt;a href="https://twitter.com/vitcord_tech?source=post_page---------------------------" rel="noopener noreferrer"&gt;tweet us&lt;/a&gt; if you liked the ADR pattern. Stay tuned and follow &lt;a href="https://dev.to/vitcord_tech"&gt;Vitcord Tech&lt;/a&gt; for more posts about our experiences and learnings 🙌&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>kotlin</category>
      <category>springboot</category>
      <category>functional</category>
    </item>
    <item>
      <title>Tearing Vitcord Backend</title>
      <dc:creator>Samuel Villaescusa Vinader</dc:creator>
      <pubDate>Thu, 18 Jul 2019 12:46:53 +0000</pubDate>
      <link>https://dev.to/vitcord/tearing-vitcord-backend-46m8</link>
      <guid>https://dev.to/vitcord/tearing-vitcord-backend-46m8</guid>
      <description>&lt;h2&gt;
  
  
  What is Vitcord? What do we do?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Vitcord&lt;/strong&gt; is a startup based in Valencia, Spain born 4 years ago.&lt;/p&gt;

&lt;p&gt;We are trying to make video stories more valuable. People share videos because they want their friends to partake in their experience: to share the mood that they're in, to see the special place they're at or the event that they're enjoying. With Vitcord, you engage with a video on a whole new level, not only with your friends, but also with people who love the same things that you love. It's an open space for video creators, where you can start telling stories with videos, and people around the world can join your stories.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbd441luy8tswdmd2tr30.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fbd441luy8tswdmd2tr30.jpeg" alt="Vitcord"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Our Monolitic API
&lt;/h2&gt;

&lt;p&gt;When we started developing Vitcord’s backend API, we couldn’t imagine ourselves at the point when we would be considering to move into a Micro-service approach. Right now, our API manages 4 main services written in &lt;strong&gt;Ruby (Ruby on Rails)&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Social Network service&lt;/strong&gt; (create a new account, follows other users, manage our profile etc)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upload and process files&lt;/strong&gt; (upload a new video, store videos, manage thumbnails etc)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manage Notifications&lt;/strong&gt; (Push notifications, notifications list etc)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Video threads&lt;/strong&gt; (create a new thread of videos, management of threads etc)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We think it was a good approach to have all the services into one API and use Rails as our main language, as we were a couple of developers and in that moment we needed to build an MVP as fast as we could to start validating if our project made sense.&lt;/p&gt;

&lt;p&gt;Now that we have validated that, and as the user base is growing, our Monolithic API is getting to its limits, so we decided to start the process of moving to Micro-service architecture like 6 months ago, with a first “service” to manage Notifications in the APP.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extracting Notifications to a Service, why?
&lt;/h2&gt;

&lt;p&gt;First of all, we are a &lt;strong&gt;Social Network&lt;/strong&gt; based on interactions between users, so you might guess that we need a tool to keep our users awake and aware about events taking place in our APP, so we have a lot of actions that end up with a &lt;strong&gt;Notification&lt;/strong&gt; stored in DB and a &lt;strong&gt;Push Notification&lt;/strong&gt;(or a pool of Push Notifications) being sent to other devices. As you might imagine, our biggest collection of items in DB is Notifications, and more than that, it is like 10 times bigger than our second biggest collection. The same for code execution, almost 70% of the time we are managing some kind of logic that will be responsible of creating a new Notification in DB + telling Firebase to send a new Push Notification.&lt;/p&gt;

&lt;p&gt;So, don’t you think it is time to keep these tasks separated? We thought the same, so we started maintaining two big modules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One that manages social network + video management (file uploading, thread management etc)&lt;/li&gt;
&lt;li&gt;Another one that manages Notifications + Push Notifications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This means each time we make a new change, normally we have to change something related to the &lt;strong&gt;first module&lt;/strong&gt; and something related to the &lt;strong&gt;second module&lt;/strong&gt;. This is something weird, as we normally want to add features or just change code attached to the first module, but as our Notifications module keeps growing, it is polluting our full code base. In the end, we encouraged ourselves to start building our first &lt;strong&gt;Microservice&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  DynamoDB over Cassandra and Kotlin over Elixir
&lt;/h2&gt;

&lt;p&gt;When we started to read about technologies to build a Notification service, we had two things clear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It would need to manage &lt;strong&gt;lot of requests per second&lt;/strong&gt; (as in Vitcord we have lots of transactional notifications)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Store millions of records per second&lt;/strong&gt; (as each transactional notification has to be saved for a user to be able to show his Notifications history)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Taking this in mind, we got to the point of taking into account a couple of languages to build it (Kotlin and Elixir) and a couple of DB technologies (Cassandra and DynamoDB).&lt;/p&gt;

&lt;p&gt;It is clear that &lt;strong&gt;Elixir&lt;/strong&gt; is probably the perfect candidate to build a Notifications service, as it leverages to Erlang VM, meaning that it is great for Scalability as it manages lightweight threads on execution and it is said that Elixir is the natural evolution of Rails (from a syntactic point of view, and also due to Phoenix likelihood with Rails). So, you might be asking &lt;strong&gt;Why did you choose Kotlin over Elixir?&lt;/strong&gt; The answer lies in the fact that no one in the team knows Elixir and we wanted to build the service fast, so we picked one guy from Backend team and one from Android (they build the APP in Kotlin) and we started the development with Kotlin + Spring. In the end, Kotlin makes sense to us as it has coroutines (lightweight threads) that covers our need of great Scalability to manage millions of requests.&lt;/p&gt;

&lt;p&gt;The same decision was taken for the DB. As you might know, &lt;strong&gt;Cassandra&lt;/strong&gt; was built thinking on scalability and high availability (with great performance) so it fits our needs as well as Elixir. When we started the development we were thinking on how to manage Cassandra nodes with a &lt;strong&gt;Kubernetes&lt;/strong&gt; cluster. We read a lot about how to manage Kubernetes (we do not have a DevOps-specific person in the team) and at the end we were talking about how much time it would take us to manage and maintain a Kubernetes cluster by ourselves, so we decided to use &lt;strong&gt;DynamoDB&lt;/strong&gt; (which is quite similar to Cassandra, but with the advantage of not needing to manage instances or clusters as it is managed by Amazon) with the promise of returning to Cassandra some day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next steps
&lt;/h2&gt;

&lt;p&gt;We are happy with our decisions, as right now for example DynamoDB gives exactly what we need for our Notifications service, and we left management up to Amazon (we know that eventually we will face big charges because of Dynamo, but we will be ready to move DB to Apache Cassandra) and Kotlin is working like a charm.&lt;/p&gt;

&lt;p&gt;Right now we are talking about how to fully separate Notifications from our Monolithic API, as for now it is working as Authentication entrance for the Notifications Service, but of course we want to keep each Microservice fully separated from each other.&lt;/p&gt;

&lt;p&gt;So those are our next steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build an &lt;strong&gt;API Gateway&lt;/strong&gt; that will work as an entrance point for our Microservices by managing routing and Authentication through an Authentication service&lt;/li&gt;
&lt;li&gt;Add an &lt;strong&gt;Event Queue&lt;/strong&gt; to our infraestructure (we are thinking on RabbitMQ or Apache Kafka) to communicate microservice actions&lt;/li&gt;
&lt;li&gt;Fully separate Notifications from the Monolithic API&lt;/li&gt;
&lt;li&gt;Add new Microservices (maybe one to manage video and files)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will cover more about our advances in next posts.&lt;/p&gt;

&lt;p&gt;Stay tuned!!&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>kotlin</category>
      <category>elixir</category>
    </item>
  </channel>
</rss>
