<?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 Nikolai Besschetnov on Medium]]></title>
        <description><![CDATA[Stories by Nikolai Besschetnov on Medium]]></description>
        <link>https://medium.com/@nikolai_23416?source=rss-762c83dbd37b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mKNtiPCIukZYlz7dbEmAQw.png</url>
            <title>Stories by Nikolai Besschetnov on Medium</title>
            <link>https://medium.com/@nikolai_23416?source=rss-762c83dbd37b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 00:21:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nikolai_23416/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[Beckenbauer - how we built own IP Firewall in Billie]]></title>
            <link>https://medium.com/billie-finanzratgeber/beckenbauer-how-we-built-own-ip-firewall-in-billie-4e5aa54789bd?source=rss-762c83dbd37b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e5aa54789bd</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[firewall]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Nikolai Besschetnov]]></dc:creator>
            <pubDate>Thu, 05 Mar 2020 15:21:34 GMT</pubDate>
            <atom:updated>2020-03-06T13:55:20.935Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-g13sRQsdZqqclcsNzWdnw.png" /><figcaption>© Illustration: Adriano García Suárez/Billie</figcaption></figure><p>As the business grows, the network traffic increases. New customers it is or merely curious beings, or dirty minds, contemplating their goals on how to abuse Billie’s infrastructure via this or that IPv4 address.</p><p>In this publication, a custom solution on how to be selective in regards to the IPv4 traffic will be described. Features HAProxy, GoLang, OSI Level 4.</p><p>Let’s roll, or use the table of contents to scroll 😏</p><h3>Table of Contents</h3><ul><li>Why Beckenbauer?</li><li>The Idea Behind Our Own IP System</li><li>Contributors to the Latency</li><li><strong>HAProxy and Golang. IP Address Blocking Solution</strong></li><li>Summary</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ct9GfL_YKLTendF530ommg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@golinchenko?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kostya Golinchenko</a> on <a href="https://unsplash.com/s/photos/m%C3%BCnich?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Why Beckenbauer?</h3><p>To avoid the hassle of signing new contracts, reduce governance processes, and save on integration time, we decided to go for our own quick &amp; robust solution — Beckenbauer.</p><p>Franz Beckenbauer was a german footballer. He made his name as a central defender. And us, the company established in Germany, felt it is going to be the name.</p><h3>The Idea Behind a Firewall</h3><p>To be in control of what IP addresses may pass, what not, according to our magic. And once the clue is there, take blocking or allowing actions!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*u8oktl7vXWNcYVOX3ckQLg.jpeg" /><figcaption>Some kind of the mediator to let the user pass or not.</figcaption></figure><p>As Billie is hosted on Amazon Cloud, one could also enhance their product security by using <a href="https://aws.amazon.com/premiumsupport/knowledge-center/waf-block-common-attacks/">Web Application Firewall (WAF)</a>.</p><h4>Amazon WAF</h4><blockquote>AWS WAF is a web application firewall that helps protect your web applications or APIs against common web exploits that may affect availability, compromise security, or consume excessive resources.</blockquote><blockquote><a href="https://aws.amazon.com/waf/">https://aws.amazon.com/waf/</a></blockquote><p>It comes in handy, e.g., in context of OWASP Top 10. This enterprise-level service gives control over how traffic reaches the applications by establishing the security rules. In addition to the rules, the following common baneful behaviors might be put under control:</p><ul><li>DDoS</li><li>Scanners and Probes</li><li><strong>IP Blacklists</strong></li><li>Bots and Scrappers</li></ul><p>One of the security rules is the “IP Match Conditions”. Sadly:</p><blockquote>An IP set can hold up to 10,000 IP addresses or IP address ranges to check.</blockquote><blockquote><a href="https://docs.aws.amazon.com/waf/latest/developerguide/waf-rule-statement-type-ipset-match.html">https://docs.aws.amazon.com/waf/latest/developerguide/waf-rule-statement-type-ipset-match.html</a></blockquote><p>And we want to provide an enormous amount of individual IP addresses dynamically—based on our magic—and block these for good (with some exceptions, e.g., expiration time)! That leaves the WAF as a suboptimal solution.</p><h4>The Middleware</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*9D-r2BUMMQH2-sXdPNEo5A.png" /></figure><p>HAProxy should not encapsulate the entire logic. Reasons why the middleware was introduced, which is another microservice.</p><p>The question, though, how would they (proxy &amp; Beckenbauer) communicate with each other? The network in any architecture causes the most significant latency comparing to other components (e.g., memory). How fast will the customer get their content, when there’s another mediator between the browser and our services?</p><h3>Contributors to the Latency</h3><p>As the system will be between the user and our services, it is inevitably going to add a lag in milliseconds to the response — the Latency. How could engineers put this factor to the minimum?</p><p>There are different reasons why the delay between a request and response may vary. The least of the problem is de-/serialization of the data. What may cause a severe or minor delay? Let’s think as if we query a modern HTTPS API Endpoint.</p><h4>Domain API Endpoint</h4><p>Typically, when you surf the internet, you’ll transfer data from/to the resource over HTTPS protocol. Not only you spend time on <strong>TLS handshake</strong>, but before you could initiate it, you have to <strong>resolve the domain name</strong>. Both of these procedures take an enormous amount of time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*flg1jKFQ8AH4Bzw0C4IaQA.png" /></figure><p>And even when you established a connection, all of the headers and other <strong>protocol shenanigans</strong> get to be exchanged. It’s three nails in the coffin, causing a severe latency.</p><h4>Direct Request by IP</h4><p>Behind each hostname is an IP address of the server. Poking the resource in the face will save us a lot of time. And HTTP itself is an add-on on top of <a href="http://www.networksorcery.com/enp/protocol/tcp.htm">TCP</a>. It establishes a connection and ensures the data delivery.</p><p>Of course, you want to ensure the shortest network distance. Avoid multiple nodes to reduce the package travel time across.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*K2SUDXA4azge5QQMoCvlTg.png" /></figure><h3>HAProxy and GoLang. IP Address Blocking Solution</h3><h4>Technology stack</h4><ul><li><strong>HAProxy</strong><br>High availability load balancer and proxy server for TCP and HTTP-based applications. To be used as a reverse proxy;</li><li><strong>Lua<br></strong>Lightweight, high-level programming language, to invoke custom logic at HAProxy’s frontend;</li><li><strong>GoLang<br></strong>For the lightweight concurrent TCP server;</li><li><strong>Redis<br></strong>Fast in-memory key-value storage, to be located close to the GoLang app for the fast IP data retrieval.</li><li><strong>AWS DynamoDB</strong><br>No-SQL Database for persistent IP addresses storage;</li><li><strong>Magic Sauce</strong><br>Collection of services used to evaluate the ip address. E.g. AbuseIPDB.</li></ul><h4>Beckenbauer &amp; HAProxy Integration</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*B1z7-Ush2dVo3xf01QwwCA.png" /></figure><p>Every request lands first on HAProxy. There you can define so-called frontends (accept requests) and backends (fulfill requests) and execute Lua scripts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*GcY4edjN-NrS7yvFSVLlNw.png" /><figcaption>HAProxy Invocation Scheme</figcaption></figure><p>There’s <a href="https://www.haproxy.com/blog/5-ways-to-extend-haproxy-with-lua/">an example</a> in the proxy’s blog. We basically copy-pasted it with a bit of alterations, e.g.</p><pre>-- Get response body, if any<br>local content = socket:receive(1)</pre><pre>-- Check if this request should be allowed<br>if content == nil or content == &quot;&quot; then<br>    core.Alert(&#39;Got no content from server&#39;)<br>    socket:close()</pre><pre>return<br>end</pre><pre>if content == &quot;1&quot; then<br>    txn:set_var(&#39;req.blocked&#39;, false)<br>elseif content == &quot;0&quot; then<br>    txn:set_var(&#39;req.blocked&#39;, true)<br>else<br>    core.Alert(string.format(&quot;Unknown content was gotten: %s\n&quot;, content))<br>end</pre><p>As for the payload, there is just an IPv4 string. A response is the one single byte 1 or 0, indicating if the reverse-proxy should process the request further or not.</p><p>In case of Beckenbauer failure (e.g., because of the timeout, which is one second), the client will be passed through the edge.</p><h4>GoLang Project</h4><p>The language is very versatile, offers you plenty of packages. It’s ridiculously simple to create a basic concurrent TCP server there, using goroutines. E.g.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33b5a8d440fb5ff7873f1bb72ea23a8e/href">https://medium.com/media/33b5a8d440fb5ff7873f1bb72ea23a8e/href</a></iframe><p>The project’s structure is a monolithic package:</p><ul><li>/cmd/server/main.go<br>The server itself;</li><li>/go.mod<br>Go Modules handle external packages;</li><li>/Makefile</li><li>/pipelines.go<br>Defines the Frontend (FE) and Backend (BE) Pipeline;</li><li>/file.go<br>Rest of GoLang files. E.g., stages for the pipelines and services.</li></ul><p>We use the pipelines to run through each stage. There are 4 of them:</p><ul><li>Find an address in the Redis;</li><li>Validate the address (whether light or heavy checks);</li><li>Persist checks;</li><li>Notify about the results.</li></ul><p>Frontend Pipeline consists of the first two stages (light checks); Backend Pipeline takes all 4 with the heavy checks flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*8LxW05RZHqYBZT25okCs1w.png" /><figcaption>Middleware’s high-level flow-chart</figcaption></figure><h4>Passive and Active Working Mode</h4><p>In the passive scenario, a decisive action is taken upon the Frontend pipeline has run. We close the TCP connection as soon as there’s a clue, whether a client may go, based on Redis records. It means that the first connection for an unknown or expired IP address will always be allowed. The average lag on the user request is about <strong>17ms</strong> in this case.</p><p>The Backend pipeline, of course, takes much more time, about <strong>250ms</strong>. When Beckenbauer needs to be extremely cautious, we don’t run FE, but just BE. On the first request, there already will be a decision.</p><p>And last but not least, once the client is blocked, we notify our Ops in Slack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*yAO9Yhu6N-gTFxpKPgvgmQ.png" /></figure><h3>Summary</h3><p>Sometimes you need to put bicycle components together. With GoLang it’s possible to prototype and create MVP, polish it to the working solution in a minimal amount of working hours. And it just works!</p><h4>Credits</h4><ul><li>To our Infrastructure Team Lead <a href="https://medium.com/@dizeee"><strong>Aleksei Vesnin</strong></a> for bringing the sanity thought to my ideas of using SQS &amp; AWS Lambda;</li><li>To our CTO <a href="https://medium.com/@artemdemchenkov"><strong>Artem Demchenkov</strong></a> for the inspiration and support.</li></ul><p>Cheers, Nikolai.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e5aa54789bd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/billie-finanzratgeber/beckenbauer-how-we-built-own-ip-firewall-in-billie-4e5aa54789bd">Beckenbauer - how we built own IP Firewall in Billie</a> was originally published in <a href="https://medium.com/billie-finanzratgeber">Billie Engineering Crew</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pub/Sub messaging within Billie]]></title>
            <link>https://medium.com/billie-finanzratgeber/pub-sub-messaging-within-billie-d5f0e2df8ac?source=rss-762c83dbd37b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5f0e2df8ac</guid>
            <category><![CDATA[pub-sub]]></category>
            <category><![CDATA[message-broker]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Nikolai Besschetnov]]></dc:creator>
            <pubDate>Thu, 10 Oct 2019 13:08:16 GMT</pubDate>
            <atom:updated>2019-10-10T21:34:52.480Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gk6Yw9huu2ndEPkTDAfm8Q.png" /><figcaption>© Illustration: Adriano García Suárez/Billie</figcaption></figure><p>Billie soon turns 3 years old from an IT perspective: since the very first repository has been created, and the first ship has set sail. And 3 years ago there were not much communication means in our monolithic application: some HTTP API endpoints, some <a href="https://www.rabbitmq.com/">RabbitMq</a> shenanigans.</p><p>Coming back to nowadays (article publication date-time), Billie became a set of microservices. And how would you imagine them — microservices — talk to each other? What about a publish/subscribe pattern? And, last but not least, how could all that be practically implemented with <a href="https://symfony.com/">Symfony</a>?</p><p>Let’s examine those questions. Under the cut, people!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZWtPSHijIvyCk2m7_JBgow.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@marius?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Marius Masalar</a></figcaption></figure><h3>Monolithic application</h3><p>Before we tap the pedal to the metal, let’s time travel 3 years in the past again. Back then, we quickly came up with an idea that a solid backend would do best to shave some time off. We were only 3 software &amp; one system engineer and a CTO to create an API, cloud infrastructure and an <a href="https://en.wikipedia.org/wiki/Single-page_application">SPA</a> to decouple responsibilities, agree on contracts and happily work in parallel to make candy.</p><p>And as it was expected, a monolithic application started to develop all problems possible. The bootstrap file became pretty much massive, which is still ok when it comes to FPM but think of all PHP consumer processes. Memory usage — that was massive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ibc9zNwti2_wOAiGb-DnBg.jpeg" /></figure><p>Anyways, such success/tragedy didn’t necessarily mean it’s the end of greenfield software for us. In fact, it was a great push &amp; motivator to make things better, without blocking the business processes.</p><h3>Segregation of responsibilities and technologies</h3><p><em>/me thumb clicks </em>and we are back to our present time! While PHP is a primary programming language in our company, some tasks are better to be done with e.g. Java or R, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/201/1*C_-rV0j8aaNsjZ5bY9dr3Q.png" /></figure><p><a href="https://martinfowler.com/bliki/StranglerFigApplication.html">Cutting our monolithic codebase down into independent services</a> pursued other goals as well. For example:</p><ul><li>Developers can work independently on their own codebases;</li><li>Microservices are faster to deploy;</li><li>Forces you to be idempotent, generally means better code quality (hella important for fin-tech);</li><li>You save resources when you need to scale your infrastructure: add only services that are required for the spike or general load.</li></ul><p>We can talk a lot about service-oriented architecture, it deserves a separate article here. But let’s focus on the cornerstone. A set of microservices is absolutely meaningless if they can’t communicate, delivering what our business has to do.</p><h3>How would microservices communicate with each other?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*erqqRHgUEHXXB1_l3Mewrw.png" /><figcaption>The platform discovers payments’ URL (e.g. set on deployment), performs API calls</figcaption></figure><p>The first idea that comes to mind would be the usage of HTTP calls (which are basically RPC calls in our case as we don’t follow RESTful) with application/json payload or query parameters.</p><p>That brings us to a question though: what if a 2nd party service is not available (I mean we could use Guzzle’s <a href="https://github.com/guzzle/guzzle/blob/master/src/RetryMiddleware.php">retry middleware</a> e.g., but what if a service is still down after a particular threshold)? Or your upstream fails with 429 HTTP codes?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*UC5M7UcA4X5Pz0LUa7_Hsw.png" /><figcaption>Platform discovered payments’ URL but after 3 attempts couldn’t get expected response</figcaption></figure><p>What if we need to call two services with the same payload? How do we discover a service’s endpoint?</p><p>Not that these problems are unsolvable, but clearly it requires some decisive actions to be taken. Why can’t we delegate all those responsibilities to an AMQP message broker?</p><h3>Our Pub/Sub architecture in RabbitMQ broker</h3><p>When we do an RPC call — that’s nothing else, but a command to the service. When a service replies—that’s basically an event, something that has happened and can’t be changed, it has its timestamp.</p><p>Similar pattern to pub/sub would be <a href="https://sourcemaking.com/design_patterns/observer">Observer</a>. However, in that case your <strong>event within a subject</strong> eventually triggers <strong>a command</strong> to tell your observers what happened. Recruiter knows their employees.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*WllTsLz6ssGZFdhtmnpnfQ.png" /><figcaption>Observer pattern</figcaption></figure><p>In publish/subscribe architecture there are no commands, only events. That means, we just need to spread news across our services and… nothing else.</p><p>Events here make your life simple and complicated at the same time. Simple, because in your app you don’t care what happens later, who’s subscribed to the topic (e.g. invoice approved). Complicated, because you don’t know what happens later (yet you can track it down by request id in the logs).</p><p>To implement the pattern, we take advantage of the <a href="https://www.rabbitmq.com/tutorials/amqp-concepts.html">AMQP model</a>. Whenever something happens in a microservice, a message goes straight to the front exchange of <strong>fanout</strong> type. That’s it. The rest of the job is done for you by a broker, ensuring that the message gets delivered to the services that are interested in such an event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5025Zlm38iRkLhQtLBd4w.png" /></figure><p>The following requirements must be met:</p><ul><li>Topic name must be a domain, e.g. Invoice or Transaction;</li><li>Destination queue must be bound to the topic exchange;</li><li>A queue itself must be durable. We don’t want to lose any messages;</li><li>In the future, it might be Invoice→ InvoiceApproved →queues. It&#39;s more semantic and clearer to understand topology, but even if we don&#39;t do it now, it doesn&#39;t affect queues (no need to disturb teams), so that could be done within the scope of Technical Friday;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*CsrSZZrTt_f_6auzEQ3tpA.png" /></figure><ul><li>Each queue must follow a naming convention, such as app_name.domain.event. E.g. payments.invoice.invoice_approved; catching such an event will initiate a payout procedure, which may cause another event that also heads out to the fanout exchange.</li></ul><p>It’s important that within a microservice, 1 queue can have only one port. That port, however, may have as many consumers as possible. This also leads to the conclusion: if a system needs to perform 2 actions on 1 event, your microservice must do it internally (pipelines or events e.g.).</p><p>At this point, we have producers, subscribers. They produce and consume payload. How do they know what kind of a payload is there? We need to define a contract! That might be plain text, JSON or…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QXrKwfgqxF-oSt88jJ4LXw.png" /></figure><h3>Serializing data with Protobuf</h3><p>As we know, an event must be immutable: data—producer emitted—must reach subscriber in exactly the same state. Both systems, independent of technology, must be able to deserialize a payload and represent it as an object, schema of which is known to each system whether it’s written in PHP or Java.</p><p>With protobuf we define our payloads in proto3 syntax. So basically once you have need to communicate between PHP and Java, you just generate classes for the corresponding language and import those to your project.</p><p>Compiled protobufs offer you serialization whether in JSON or binary out of the box. Finally, having our data, it’s right about time to wrap the payload up in RabbitMQ message, accompanying it with a few headers:</p><ul><li>X-Request-ID<br>To trace request flow-through systems. Read more here “<a href="https://medium.com/billie-finanzratgeber/no-log-shall-be-lost-13495bca505e">No log shall be lost</a>”;</li><li>X-Message-Type<br>To tell subscribers what payload is in there.</li></ul><p>You can read <a href="https://medium.com/billie-finanzratgeber/why-plumb-json-when-you-can-protobuf-1cfb3681e4e2">an awesome article</a> regarding protobuf usage in one of Billie’s R services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4bETCnImeDsd8fBePwiEFg.png" /></figure><h3>Practical example with Symfony4</h3><p>Since I’ve mentioned PHP, why don’t we take a look at a practical example of pub/sub with Symfony4? There we use the <a href="https://symfony.com/doc/current/components/messenger.html">messenger component</a> in conjunction with <a href="https://github.com/php-enqueue">Enqueue</a>.</p><p>To get started, one just requires a composer package from our private repository composer require ozean12/amqp-pack. It will pull all dependencies, including the protobuf generated PHP classes. Once it’s there, you’ll witness a stock config/packages/messenger.yaml configuration file.</p><p>Each microservice has to declare transports: whether it is for publishing or consuming. Sample configuration might be like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7507346e02573a3f85f6a4ca9c331352/href">https://medium.com/media/7507346e02573a3f85f6a4ca9c331352/href</a></iframe><p>It’s possible to publish/consume messages via transport. It doesn’t look developer-friendly, however, you can clearly see a pattern there. Something for future improvements.</p><p>Before we create our first producer or consumer, we need a transport factory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02826b86a1b1404303f79b2248c800e5/href">https://medium.com/media/02826b86a1b1404303f79b2248c800e5/href</a></iframe><p>It is a stock configuration with one exception, the debug flag (3rd argument) is set to false. Debugging doesn’t do anything useful, except for creation of queues and exchanges on the fly. Unfortunately, it has no idea about fanout exchange, so any attempt to publish a message will always crash as the bundle expects topic exchange. Then again, why would you like to have queues creation in runtime?</p><p>We are all set!</p><h4>Publishing a message is trivial</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12b58ab1e70625d0dfff94b905c8eac3/href">https://medium.com/media/12b58ab1e70625d0dfff94b905c8eac3/href</a></iframe><h4>So is subscribing &amp; consuming</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f39996956aae6714abde08a4fa1ce8d/href">https://medium.com/media/4f39996956aae6714abde08a4fa1ce8d/href</a></iframe><p>Now just run your consumer bin/console messenger:consume invoice.invoice_approved -vvv and enjoy happy communication!</p><h3>Circuit breaker for PHP consumers</h3><p>For PHP it’s natural process to get executed and quit the process with exit code zero. Of course, you could make use of <a href="https://www.php.net/manual/en/book.pcntl.php">process control</a>, but in our case consumers terminate after they ack a bunch of messages. Unhandled exceptions cause a process to quit with non-zero exit code.</p><p>At some point, you may face the situation when the process always fails and the message gets redelivered. First of all, your logging facilities gonna be cluttered and you may do unnecessary calls to 3rd parties. It’s handy to have a circuit breaker.</p><blockquote>The basic idea behind the circuit breaker is very simple. You wrap a protected function call in a circuit breaker object, which monitors for failures. Once the failures reach a certain threshold, the circuit breaker trips, and all further calls to the circuit breaker return with an error, without the protected call being made at all. Usually you’ll also want some kind of monitor alert if the circuit breaker trips.</blockquote><blockquote><a href="https://martinfowler.com/bliki/CircuitBreaker.html">Martin Fowler</a></blockquote><p>In our case, we just track exit codes. If it’s not zero — something went wrong. Having such a trivial tool helps a lot to cut costs.</p><h3>Conclusion</h3><p>Pub/Sub helps a lot with service discovery and reliability, scaling. It makes your code idempotent and robust. However it can’t replace remote procedure calls, we still have old good HTTP APIs, which someday gotta be replaced with gRPC. There’s a whole new world of communication: transactions, streams.</p><p>Thank you for your attention! Have any questions? A comment section is below!</p><p>Best regards, Nikolai.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5f0e2df8ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/billie-finanzratgeber/pub-sub-messaging-within-billie-d5f0e2df8ac">Pub/Sub messaging within Billie</a> was originally published in <a href="https://medium.com/billie-finanzratgeber">Billie Engineering Crew</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Hospital]]></title>
            <link>https://medium.com/billie-finanzratgeber/data-hospital-402310dc2eae?source=rss-762c83dbd37b------2</link>
            <guid isPermaLink="false">https://medium.com/p/402310dc2eae</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[symfony]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Nikolai Besschetnov]]></dc:creator>
            <pubDate>Thu, 12 Oct 2017 19:13:15 GMT</pubDate>
            <atom:updated>2017-10-12T19:42:53.454Z</atom:updated>
            <content:encoded><![CDATA[<h4>Sick way to treat your byte hazardous patients.</h4><h3>The Problem</h3><p>Billie is integrated with numerous of external services that provide us e.g. customer bank data, risk reports, etc. There is entirely no guarantee that a service has 24/7 uptime or the data they provide is unquestionably correct and complete. Eventually, “<em>fide sed cui vide”</em> kicks in. We need an ecosystem to ensure the validity of incoming (relatively untrusted) bytes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qeTJsJtcLKLWfkngDfS1RQ.png" /><figcaption>© Illustration. Caterina Carraro/Billie.</figcaption></figure><h3>The Solution</h3><blockquote><strong>Data</strong><br>Data is raw, unorganized facts that need to be processed. Data can be something simple and seemingly random and useless until it is organized.</blockquote><blockquote><strong>Information</strong><br>When data is processed, organized, structured or presented in a given context so as to make it useful, it is called information.</blockquote><blockquote>Source: <a href="http://www.diffen.com/difference/Data_vs_Information">http://www.diffen.com/difference/Data_vs_Information</a></blockquote><p>Hospital tries to transform data into information, if possible. If not, then the service will fulfill a diagnoses board, meaning the processing of data is no longer possible. But one step at a time.</p><h3>Strategy inception</h3><p>What regular hospital looks like? Patients, doctors, diagnoses… To diagnose, a doctor must have some knowledge base. Firstly one needs to understand what’s wrong (if any) with the patient and then apply different methodologies to cure a sick man.</p><p>When data comes, it eventually gets wrapped (becomes a patient) and then goes to a hospital. Patient already might have some diagnoses. Therefore he comes to the medical institution with his board (ideally it’s empty).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76c0d1fefdfdf0378a52d49ecd8f3046/href">https://medium.com/media/76c0d1fefdfdf0378a52d49ecd8f3046/href</a></iframe><p>The patient goes to every doctor, and the latter one decides can he work with that visitor or not. If yes, then prescriptions are invoked. Data specialist iterates over and checks if one fits the patient’s state. In case of a match: prescription strategies to be run. Or not. Here’s flow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*dbSLciY8xl9E7onZhphb3w.png" /><figcaption>Patient service flow.</figcaption></figure><p>When executing the prescriptions (including or not the strategies) we add diagnoses to the board. Diagnosis can be different: good or bad.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cba6e429891907775a2dd08a3b1d27cd/href">https://medium.com/media/cba6e429891907775a2dd08a3b1d27cd/href</a></iframe><p>Hospital in every case must deliver at least one diagnosis. Ideally, it has to state that the patient is healthy and no any actions need to be taken.</p><p>Did you notice the healed severity? Indeed, doctors here are not just to write down the positive or negative conclusions regarding patient’s health. They also are supposed to cure our poor fellow.</p><p>Imagine we got data related to customer’s bank account. And all of a sudden there’s no IBAN! Sad. But hey, there’s account number, and we know bank’s code. So here comes the prescription: <em>use those two values and create German IBAN, update patient’s state</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36896aaefdbfddac0d4e5e86a1c2291a/href">https://medium.com/media/36896aaefdbfddac0d4e5e86a1c2291a/href</a></iframe><p>Another upcoming strategy will check if IBAN is empty. If it’s empty, then a diagnosis will be unpleasing and later on proceeded by other services, e.g. create an HTTP exception and deliver it to frontend or Slack or Sentry or wherever.</p><h3>Usage in Symfony3</h3><p>Doctors, Prescriptions, and their Strategies are defined as <a href="https://symfony.com/doc/current/components/dependency_injection.html">services</a>. The entire configuration is set in YAML file, thanks to <a href="http://symfony.com/doc/current/service_container/tags.html">tagging</a> and <a href="https://symfony.com/doc/current/service_container/compiler_passes.html">compiler passes</a>. I’ve mentioned the IBAN prescription strategy. Now let’s see how will it look like in action.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a37188aff23d5fe89829cb5b4bb081a0/href">https://medium.com/media/a37188aff23d5fe89829cb5b4bb081a0/href</a></iframe><p>Once the services are defined and tagged, right about time to compile them (don’t forget to include the configuration file).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b623f58c8b82791d5e12cef48407588/href">https://medium.com/media/8b623f58c8b82791d5e12cef48407588/href</a></iframe><p>That’s it. Now, let’s introduce new hospital to patients.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86d0bcc95956dc67a6a495766b192613/href">https://medium.com/media/86d0bcc95956dc67a6a495766b192613/href</a></iframe><h3>Summary</h3><p>Now you are ensured that after the health check, the part of your system — that relies on information you get from your provider — won’t be turned into exceptions dust.</p><p>The system, in the end, is highly decoupled and rich of SRP. You can combine strategies with different prescriptions and even doctors. With time, men in white become brainy, making your system much more responsive and smart.</p><p>Thank you for attention, have fun! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=402310dc2eae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/billie-finanzratgeber/data-hospital-402310dc2eae">Data Hospital</a> was originally published in <a href="https://medium.com/billie-finanzratgeber">Billie Engineering Crew</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>