TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

My thoughts about Fly.io (so far) and other newish technology I'm getting into

130 pointsby hartleybrodyabout 3 years ago

23 comments

simonwabout 3 years ago
&gt; It seems like this would add a whole new class of bugs, like “I just submitted a form to change a setting and when the page reloaded, it still showed my previous value in the form” – since the write hadn’t propagated to the local read replica yet.<p>There&#x27;s a very solid solution to this that isn&#x27;t as widely known as it should be.<p>Read after write consistency is extremely important. If a user makes an edit to their content and then can&#x27;t see that edit in the next page they load they will assume things are broken, and that the site has lost their content. This is really bad!<p>The best fix for this is to make sure that all reads from that user are directed to the lead database for a short period of time after they make an edit.<p>The Fly replay header is perfect for this. Here&#x27;s what to do:<p>Any time a user performs a write (which should involve a POST request), set a cookie with a very short time expiry - 5s perhaps, though monitor your worst case replica lag to pick the right value.<p>I have trust issues with clocks in user&#x27;s browsers, so I like to do this by including a value of the cookie that&#x27;s the server-time when it should expire.<p>In your application&#x27;s top-level middleware, look for that cookie. If a user has it and the court time has not been reached yet, send a Fly replay header that internally redirects the request to the lead region.<p>This guarantees that users who have just performed a write won&#x27;t see stale data from a lagging replica. And the implementation is a dozen or so lines of code.<p>Obviously this won&#x27;t work for every product - if you&#x27;re building a chat app where every active user writes to the database every few seconds implementing this will send almost every piece of traffic to your leaders leaving your replicas with not much to do.<p>But if your application fits the common pattern where 95% of traffic are reads and only a small portion of your users are causing writes at any one time I would expect this to be extremely effective.<p>Fly replay headers are explained in detail here: <a href="https:&#x2F;&#x2F;fly.io&#x2F;blog&#x2F;globally-distributed-postgres&#x2F;" rel="nofollow">https:&#x2F;&#x2F;fly.io&#x2F;blog&#x2F;globally-distributed-postgres&#x2F;</a>
评论 #31434217 未加载
评论 #31434906 未加载
rkangelabout 3 years ago
I think his stack is a little confused. He&#x27;s got HTMX <i>and</i> Phoenix in there.<p>If you are using Phoenix then LiveView is the obvious approach to dynamically updating a page based on server stuff. It&#x27;s a similar-ish architecture to HTMX, but integrated into the framework. The page is rendered on the server as normal, then when it loads on the client a web-socket is opened to a task on the server (page includes the LiveView JS). Then when something changes on the server, some new HTML generated and then the parts that have changed are sent down the websocket to the client to insert into the page. LiveView is part of Phoenix, leverages Elixir&#x27;s concurrency, is very performant and a joy to use.<p>HTMX is a way of getting similar functionality but for a conventional server rendered framework like Django which doesn&#x27;t have any of this stuff built in. It would be challenging to build it in anyway because the concurrency isn&#x27;t as powerful. Simplistically, Phoenix exists because Chris McCord was trying to do a LiveView equivalent in Ruby, had issues, went on a search discovered Elixir.<p>So either use:<p>Elixir + Phoenix + Phoenix LiveView<p>Or:<p>Python + Django + HTMX (Python and Django can be substituted for other frameworks like Rails)<p>In both cases, Alpine can then be useful to sprinkle in some clientside only UI features.
评论 #31436781 未加载
评论 #31433479 未加载
评论 #31433129 未加载
评论 #31434110 未加载
chrismccordabout 3 years ago
One of the points about read replicas and read-your-own-writes is correct to call out, but on the Elixir side we have an answer to that:<p>&gt; It seems like this would add a whole new class of bugs, like “I just submitted a form to change a setting and when the page reloaded, it still showed my previous value in the form” – since the write hadn’t propagated to the local read replica yet.<p>Elixir is distributed out of the box, so nodes can message each other. This allowed us to easily ship a `fly_postgres_elixir` library that guarantees read-your-own-writes: <a href="https:&#x2F;&#x2F;github.com&#x2F;superfly&#x2F;fly_postgres_elixir" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;superfly&#x2F;fly_postgres_elixir</a><p>It does this by sending writes to the primary region over RPC (via distributed elixir). The write is performed on a primary instance adjacent to the DB, then the result, <i>and the postgres log-sequence-number</i>, is sent back to the remote node. When the library gets a result of the RPC write, it blocks locally until its local read replica matches an LSN &gt;= write LSN, then the result is returned to the caller<p>This gives us read-your-own-writes for the end-user, and the calling code remains unchanged for standard code paths. This doesn&#x27;t solve all classes of race conditions – for example you may broadcast a message over Phoenix.PubSub that causes a read on the remote node for data that isn&#x27;t yet replicated, but typically you&#x27;d avoid an N query problem from pubsub in general by populating the data in the message on the publisher beforehand.<p>There&#x27;s no completely avoiding the fact you have a distributed system where the speed of light matters, but it&#x27;s Fly&#x27;s (and Phoenix&#x27;s) goal to push those concerns back as far as possible. For read heavy apps, or apps that use caching layers for reads, developers already face these kinds of problems. If you think of your read-replicas as cache with a convenient SQL interface, you can avoid most foot guns.<p>I&#x27;m happy to answer other questions as it relates to Phoenix, Fly or what Phoenix + Fly enables from my perspective.
评论 #31434234 未加载
csmpltnabout 3 years ago
An unrelated, yet honest question.<p>There have been many posts hitting the HN frontpage regarding fly.io recently. Is it healthy to have so much content about a single PAAS platform showing up here so often now?
评论 #31431888 未加载
评论 #31432123 未加载
评论 #31435853 未加载
评论 #31434006 未加载
评论 #31431832 未加载
评论 #31432291 未加载
评论 #31433006 未加载
评论 #31432018 未加载
评论 #31432555 未加载
评论 #31431918 未加载
评论 #31431849 未加载
评论 #31432090 未加载
评论 #31435367 未加载
评论 #31431923 未加载
tptacekalmost 3 years ago
Just a quick note that the list of applications for Fly.io at the end of this post was taken from our Launch HN --- <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22616857" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22616857</a> --- and we&#x27;ve changed (expanded) since then.<p>When we launched, we didn&#x27;t do persistent storage for instances, so it didn&#x27;t make as much sense to run ordinary apps here; rather, the idea was that you&#x27;d run your full-stack app somewhere like us-east-1, and carve off performance-sensitive bits and run them on Fly.io. That&#x27;s &quot;edge computing&quot;.<p>But a bit over a year ago, we added persistent volumes, and then we built Fly Postgres on top of it. You can store files on Fly.io or use a bunch of different databases, some of which we support directly. So it makes a lot more sense to run arbitrary applications, like a Rails or Elixir app, which is not something we would have said back in March 2020.
nicoburnsabout 3 years ago
&gt; But despite how much I want to learn the fly.io platform – it has been a bit tricky for me wrap my head around a good use-case for this type of distributed hosting service.<p>Worth noting that you don&#x27;t have to use the distributed aspect. I have my site hosted on a single one of a fly.io&#x27;s smallest instances (which one can get 3 of for free), and even like this the performance is <i>excellent</i> (50ms response times), and it doesn&#x27;t have the problem of spinning down when not in use like Heroku&#x27;s free tier.<p>It&#x27;s nice to at least get a choice of regions. For example, the company I work for (not hosted on fly.io currently) only has customers in the UK and Ireland. So it&#x27;s would be to be able to pop our servers there with a simple config setting.
评论 #31434070 未加载
评论 #31436828 未加载
davidkuennenabout 3 years ago
Do many companies actually need databases geolocated near users?<p>I&#x27;m working on big and small projects&#x2F;companies and that has never been any concern of ours.<p>I always imagined it to be something only the very very big players care about. And as a big player I would usually bet on a big partner like AWS, GCP, Azure. Or am I missing something?
评论 #31433635 未加载
评论 #31434151 未加载
评论 #31432324 未加载
评论 #31432427 未加载
评论 #31433242 未加载
malikerabout 3 years ago
I’ve used fly.io for a couple new projects. The main thing I like about it is that it supports affordable and easy to use persistent volumes, something the container services (GCP, AWS) don’t. This lets me test locally with volumes in a way that is identical to how things will work when deployed. With the other container hosts, I’ve had to refactor to use cloud storage services like S3.<p>Fly.io also has a clean, highly usable CLI and minimal set of services unlike the hundreds of options on other providers. But that’s just icing on top—the volume support is the big advantage for me.
pwabout 3 years ago
The end of this article raises the issue of whether Fly.io’s USP, deploying app servers close to your users, is useful for run of the mill web apps. And as much as I like Fly.io and the people associated with it, I’ve wondered this myself. It just seems like serving to US customers from any major US data center is generally fast enough. And I think this might even be true for the world of HTML-over-the-wire web stuff, which Fly.io seems to investing heavily in.<p>No doubts there are plenty of more niche uses (if I were serving users internationally, I’d probably use Fly.io), but the use case just doesn’t seem as broad as the Heroku&#x2F;PaaS comparisons make it out to be.
评论 #31432293 未加载
satyrneinabout 3 years ago
<i>Tired of SPA complexity? Try server side rendering, now with websockets, globally distributed nodes, read replicas, and eventual consistency!</i><p>All of this tech sounds cool, but like the author, I&#x27;m unsure when it&#x27;s called for.
评论 #31435009 未加载
zoomzoomalmost 3 years ago
There&#x27;s been a lot of talk about fly.io lately - it&#x27;s clearly an awesome and exciting platform. But I&#x27;d have to agree with the author here that it doesn&#x27;t solve the core problems faced by most web devs and web dev teams.<p>There are 3 relevant (for this comment) &quot;performance layers&quot; in building software:<p>- Cycle time of a team or of the project - this is affected the most by language&#x2F;framework choice, DevOps infrastructure, and team working style - this should be measured in days&#x2F;weeks<p>- Feedback loop for an individual dev working on a new ticket - this is based on the team&#x27;s cycle time but in addition is really about the dev environment, team collaboration, how the team maintains quality, and how well-defined work is before being started - this should be measured in muinutes&#x2F;hours<p>- Performance of the software deployed in terms of response time to end users - milliseconds<p>Fly.io helps the most with category #3. But how often is that really the most important issue in choosing where to deploy your app? If an alternative made small sacrifices there (for example went form 99.99% performance to 99%) but gained velocity for individual devs and the team to be able to ship better product more quickly, would the company&#x2F;project be better off?<p>At Coherence (www.withcoherence.com) - disclosure that I&#x27;m a cofounder - we&#x27;re laser-focused on a post-Heroku development platform that goers further than Heroku on categories 1 &amp; 2 above (where I&#x27;d argue Heroku is still the gold standard) rather than focusing on category 3.<p>We&#x27;re super early but in closed beta - if it sounds exciting please check us out and request a demo on the site!
kifabout 3 years ago
&gt; But despite how much I want to learn the fly.io platform – it has been a bit tricky for me wrap my head around a good use-case for this type of distributed hosting service.<p>The distributed features are there for when you need them – I don&#x27;t think you have to use them. Or am I missing something?
Dave3of5about 3 years ago
A little note about read replicas and problems I&#x27;ve discovered. It&#x27;s often the case in code that you write a value to the DB then immediately read it back often in the form of a different query somewhere else.<p>If you are setup to do some kind of a round robin read from the read replicas you can often get a different read from what you wrote as the value hasn&#x27;t replicated to your read replicas yet. The solution is to use the write endpoint when reading after a write.<p>He says that here but just wanted to point out that it can happen inside an api and cause real issues with data.
评论 #31432054 未加载
Mo3almost 3 years ago
Fly.io, as sorry as I am to say, does not come close to the functionality Heroku offers yet.<p>Redis instances are single-region single-replica, for example.<p>On another note, as soon as they offer serverless functions and solid redundant Redis + SQL I&#x27;ll be thinking about moving some of our production services over there for a test run.
评论 #31437310 未加载
tlarkworthyabout 3 years ago
Cloud Run is an alternative to fly.io that scales to zero so it can be much cheaper but with added cold starts.
评论 #31434752 未加载
评论 #31432144 未加载
ewalk153about 3 years ago
Flyio does promote a pattern for avoiding the distributed write database complexity: request replay, a single main write database, and replicated read dbs.\1<p>When a request comes in to write on a read server that attempt a db write, the request is aborted and replayed on the main write server.<p>With some clever assumptions such as “get requests rarely write to the db” and “post request usually do”, much of the write traffic can skip the read vms.<p>They created a ruby rack middleware\2 to standardize this pattern for Ruby on Rails.<p>\1 <a href="https:&#x2F;&#x2F;fly.io&#x2F;blog&#x2F;run-ordinary-rails-apps-globally&#x2F;" rel="nofollow">https:&#x2F;&#x2F;fly.io&#x2F;blog&#x2F;run-ordinary-rails-apps-globally&#x2F;</a><p>2\ <a href="https:&#x2F;&#x2F;github.com&#x2F;superfly&#x2F;fly-ruby" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;superfly&#x2F;fly-ruby</a>
评论 #31433229 未加载
Stampo00almost 3 years ago
I&#x27;m enjoying fly.io so far.<p>I just dropped DigitalOcean because of their price hike. No hard feelings. I was barely using it, and the product is growing more towards full-featured apps and teams, which is not as good a fit for me, an individual just screwing around. I don&#x27;t fault them. I&#x27;m not their target customer.<p>Fly.io is very much designed for use primarily via their CLI tool. Their web interface needs some polish. But it does everything it says on the tin, for a price that&#x27;s more than reasonable.<p>I only used Heroku briefly so I can&#x27;t comment on similarities or differences with any authority.<p>As someone who is already very comfortable with container-based development, I&#x27;m happy with fly.io.
marbanabout 3 years ago
I found render.com more convincing than fly.io (which looked more like a beta product with a prime-time landing page), with both of them not being anywhere close to making me jump from GCP.
jjdeveloperabout 3 years ago
I’m unsure why you would need HTMX and alpine. Phoenix I believe is capable of handling what both of those would provide, or perhaps I’m missing something?
dfeeabout 3 years ago
I’ve got a deploy running on Fly.io, but I didn’t go with the buildpack option; instead I’m pushing a locally built docker image (buildpacks don’t support pnpm).<p>One big miss, though, is you’ll still need a database and s3, so I’m not sure if I totally understand the value.
julianbuseabout 3 years ago
I think some things need to be built out some more, like their postgres and adding more storage after creation, but in general it&#x27;s really enjoyable to use. The pricing seems fair, and their blog is intersting and fun to read.
评论 #31432983 未加载
bilateralmost 3 years ago
Noob question but don&#x27;t Netlify and Vercel do this already at least for Next.js apps (cache to the edge, run serverless functions on edge nodes etc)?
dom__inicabout 3 years ago
Unrelated to this topic, but I think you should apply this one line of CSS to your stylesheet - it improves your text aesthetics and readability :)<p>html { -webkit-font-smoothing: &quot;antialiased&quot; }
评论 #31446244 未加载