{"id":9319,"date":"2019-09-17T11:17:24","date_gmt":"2019-09-17T14:17:24","guid":{"rendered":"http:\/\/blog.plataformatec.com.br\/?p=9319"},"modified":"2019-09-17T14:29:58","modified_gmt":"2019-09-17T17:29:58","slug":"using-broadway-at-hexdocs-pm","status":"publish","type":"post","link":"http:\/\/blog.plataformatec.com.br\/2019\/09\/using-broadway-at-hexdocs-pm\/","title":{"rendered":"Using Broadway at Hexdocs.pm"},"content":{"rendered":"\n
This is a quick blog post about our experience replacing Hexdocs.pm<\/a>\u2019s GenStage<\/a> pipeline with Broadway<\/a>.<\/p>\n\n\n\n To give some background information, Hexdocs.pm<\/a> started out as basically just static file hosting for documentation. With the introduction of private Hexdocs<\/a> it became a distinct Elixir application. Over time, we have also moved handling of documentation tarballs there to offload API servers. Instead of API servers doing all the work, they now just upload a tarball to S3 which automatically sends a SQS<\/a> message which is then picked up by the Hexdocs app. The initial implementation of Hexdocs pipeline was done with a custom GenStage producer and a consumer.<\/p>\n\n\n\n Updating the pipeline to use Broadway was really straightforward. We\u2019ve completely removed our custom producer and replaced it with BroadwaySQS.Producer<\/a>. In terms of consuming messages, our code is pretty much unchanged, instead of implementing Previously, we needed to configure our supervision tree to start X producers and Y consumers, and set consumers to be subscribed to producers. With Broadway, we specify the desired topology and it starts all processes under a dedicated supervisor. Not only it\u2019s a more declarative approach, Broadway automatically adds a \u201cTerminator\u201d process to the supervision tree that ensures proper application shutdown. While before the application could abort a job in the middle of processing, now Broadway ensures the job queue is drained before shutting down the app.<\/p>\n\n\n\n On the testing front, we didn\u2019t start our GenStage pipeline at all during tests to avoid doing network requests, and we tested the logic through internal APIs. Now, we\u2019re conditionally using Perhaps the biggest win by moving over to Broadway was that it automatically batches and acknowledges messages. This, along with other existing and planned future features like rate-limiting and backoff, is what is most appealing about Broadway – that the community best practices will usually be the default behaviour or just a matter of configuration.<\/p>\n\n\n\n Overall, we were very happy with updating Hexdocs to use Broadway and we\u2019ve been running it in production for last few months without issues. Not only we removed a lot of code, we got a couple nice features for free and we will continue to reap the benefits as Broadway gets updated.<\/p>\n\n\n\n See hexpm\/hexdocs#11<\/a> to see all required code changes.<\/p>\n","protected":false},"excerpt":{"rendered":" This is a quick blog post about our experience replacing Hexdocs.pm\u2019s GenStage pipeline with Broadway. To give some background information, Hexdocs.pm started out as basically just static file hosting for documentation. With the introduction of private Hexdocs it became a distinct Elixir application. Over time, we have also moved handling of documentation tarballs there to offload API servers. Instead of API servers doing … \u00bb<\/a><\/p>\n","protected":false},"author":70,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[1],"tags":[143],"aioseo_notices":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts\/9319"}],"collection":[{"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/users\/70"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/comments?post=9319"}],"version-history":[{"count":6,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts\/9319\/revisions"}],"predecessor-version":[{"id":9325,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/posts\/9319\/revisions\/9325"}],"wp:attachment":[{"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/media?parent=9319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/categories?post=9319"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.plataformatec.com.br\/wp-json\/wp\/v2\/tags?post=9319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}GenStage.handle_events\/3<\/code><\/a> callback we now implement
Broadway.handle_message\/3<\/code><\/a>.<\/p>\n\n\n\n
Broadway.DummyProducer<\/code><\/a>, which doesn\u2019t hit the network, and we\u2019re triggering an event in the pipeline using
Broadway.test_messages\/2<\/code><\/a> making the test more realistic.<\/p>\n\n\n\n