HNHacker News
TopNewBestAskShowJobs

brandur

3,383 karma · joined August 30, 2011

APIs + engineering @ River. Ex-Snowflake. Ex-Stripe. Ex-Heroku.

Twitter: https://twitter.com/brandur

GitHub: https://github.com/brandur

Website: https://brandur.org

Email: brandur@brandur.org

submissionscomments
brandur··on The notifier pattern for applications that use Postgres
Author here. The behavior of notify with respect to transactions is indeed notable, and definitely a great feature that makes them distinct from pub/sub in other systems. Notifies fire only when data is ready after the transaction is committed, and they're also deduplicated based on payload so listeners don't have to react to many of the same message unnecessarily.

That said, NOTIFY isn't really what this post is about. It concerns itself with the other half of listen/notify by describing a "notifier" pattern, one which listens via `LISTEN` statements and distributes them application subcomponents to help maximize economy around the use of Postgres connections.

brandur··on The notifier pattern for applications that use Postgres
Listen does hold a connection, but that doesn't mean it defeats connection pooling.

That's what I was trying to convey in this blog post: you'll keep a fixed number of connections open for use with listen, but as few as possible by reusing a single connection per program to simultaneously listen on all channels that your application cares about (with the notifier distributing messages to each internal component that subscribed).

With your dedicated listen connections accounted for, the rest of the connection pool can operate normally, with programs checking connections in and out only as long as they need them.

So the net-net is that you have a handful of connections dedicated for listen, and the remaining ~hundreds are part of the connection pool for shared use.

brandur··on The Stainless SDK Generator
That's interesting — the typed request and response objects that you get with an API SDK are certainly one of the biggest upsides, and I certainly see the benefit of having full control of the transport layer yourself so that you can add any common telemetry / logging / statistics at your leisure.

On the other hand, a benefit of a more complete API is that in typed languages you can tab-complete your way to success. With each endpoint a function and all the requisite configuration (API URL, etc.) bundled in, for basic integrations you may never even have to reference documentation, or if you do, very little of it, as your IDE finds functions/properties for you and you can read documentation right out their docstrings.

brandur··on The Stainless SDK Generator
I helped maintain the public API language bindings at Stripe for many years, and although I'd defend it to the death as the right DX (SDKs are so much easier to use than raw web APIs), it's hard to appreciate just how onerous of a process this was before Alex pioneered a codegen-based solution.

Some of the language SDKs were dynamic (e.g. Ruby, Python) and could adapt automatically to small API changes like if a new field was added in a response. Some were not (e.g. Java, Go), and for every API change, someone had to manually make the change to that SDK's codebase (add a field, add a struct, add a function for a new endpoint), get it reviewed and merged, and cut a release. As Stripe got bigger and there were API changes all the time, the only way this was even remotely functional was that we had a couple heroic workhorses that'd watch for changes and open hundreds of PRs a year for them. Honestly, in retrospect, it's amazing this even worked.

Getting everything switched over to a generated solution was an arduous process because the new generated code had to be API-compatible with the existing code so that the cutover to generated bindings didn't break every Stripe user under the sun. We eventually got there, but it took a long time.

I like Stainless' mission because after seeing the crazy maintenance hassle that all of this was at Stripe, I think it makes way more sense to save all that engineering time for your more concerns, and outsource this problem to someone else. A plug-and-play way of getting high quality SDKs in all common languages that get pushed to appropriate repositories for distribution and comes with quality companion documentation.

We've actually had pretty good luck at my current job with open source tools like openapi-generator [1], but this sort of codegen is so convoluted that the sustainability of a pure open source solution makes me a little afraid, and you still end up doing a lot of the last mile work yourself.

---

[1] https://github.com/OpenAPITools/openapi-generator

brandur··on River: A fast, robust job queue for Go and Postgres
There's a lot to be said about the correctness benefits of a transactional model.

The trouble with hitting an HTTP API to queue a task is: what if it fails, or what if you're not sure about whether it failed? You can continue to retry in-band (although there's a definite latency disadvantage to doing so), but say you eventually give up, you can't be sure that no jobs were queued which you didn't get a proper ack for. In practice, this leads to a lot of uncertainty around the edges, and operators having to reconcile things manually.

There's definite scaling benefits to throwing tasks into Google's limitless compute power, but there's a lot of cases where a smaller, more correct queue is plenty of power, especially where Postgres is already the database of choice.

brandur··on River: A fast, robust job queue for Go and Postgres
Author here.

Wanting to offload heavy work to a background job is absolute as old of a best practice as exists in modern software engineering.

This is especially important for the kind of API and/or web development that a large number of people on this site are involved in. By offloading expensive work, you take that work out-of-band of the request that generated it, making that request faster and providing a far superior user experience.

Example: User sign-up where you want to send a verification email. Talking to a foreign API like Mailgun might be a 100 ms to multisecond (worst case scenario) operation — why make the user wait on that? Instead, send it to the background, and give them a tight < 100 ms sign up experience that's so fast that for all intents and purposes, it feels instant.

brandur··on San Francisco is becoming a tech hub again, Y Combinator CEO says
There's a little bit of editorializing in the title, but Garry's basic contention is that YC is firing on all cylinders, and it's headquartered in SF:

> Jamali: It’s kind of interesting — so that narrative is there, but are you saying at the same time that there is this comeback happening, that maybe a lot of people outside of San Francisco haven’t appreciated? A comeback that’s being driven by the tech industry?

> Tan: Yeah, at the end of the day, what we want is prosperity. And the coolest thing in the world is that at Y Combinator, we get to see two or three people come together from any background, from any country in the world, and they have a fair shot here. They get half a million dollars, and they can go and try to create something that touches a billion people. And that’s really what we try to do every day. And if they succeed, they’ll have thousands of employees, and these are good, high-paying jobs in tech. And that will actually create so much prosperity for the whole community, that that’s actually why San Francisco is so awesome.

Not so much in the interview, but a common claim is that many of the most important AI companies like OpenAI and Anthropic are located in the city, so there's a bit of an AI boom going on.

For general context though, Garry's part of the crowd that's committed to staying in San Francisco and getting involved in local politics to make the city better. Whether or not you agree, he's definitely going to have an intentional pro-SF bias in general, which he'd acknowledge.

brandur··on 17.1 Salesforce Towers worth of empty office space spread across SF
> Actually, who am I kidding- some other interest group would probably take their place.

This is it unfortunately.

After observing the SF NIMBY mentality for many, many years, you start to see the matrix. It has nothing to do with gentrification, inclusion, environmentalism, or any of the other purported values. It's about one thing: stasis. Keeping SF the same at all costs, and making sure no new people come here.

San Franciscans favorite subject right now is talking about how downtown commercial space could be converted to housing, but make no mistake, the second anyone actually tried to do that, the backslash would be powerful and instantaneous. (And it's already so impossible to do between zoning and regulation that it doesn't even need backlash to already be infeasible.)

brandur··on GitHub's User Content certificate has expired
It's also the domain used for releases and other artifacts (after a redirect from github.com). There's going to be a lot of broken builds today:

    $ curl -i -L https://github.com/kyleconroy/sqlc/releases/download/v1.17.0/sqlc_1.17.0_linux_amd64.tar.gz
    HTTP/2 302
    server: GitHub.com
    date: Fri, 24 Mar 2023 20:51:56 GMT
    content-type: text/html; charset=utf-8
    location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/193160679/09048595-c7f4-45b5-858a-7f55baa2fd7d?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230324%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230324T205156Z&X-Amz-Expires=300&X-Amz-Signature=772d0aa8c5c19b0a5ef84d718d2faf0d81f24b224a4ef634d2410787e8f50bad&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=193160679&response-content-disposition=attachment%3B%20filename%3Dsqlc_1.17.0_linux_amd64.tar.gz&response-content-type=application%2Foctet-stream

    curl: (60) SSL certificate problem: certificate has expired
    More details here: https://curl.se/docs/sslcerts.html

    curl failed to verify the legitimacy of the server and therefore could not
    establish a secure connection to it. To learn more about this situation and
    how to fix it, please visit the web page mentioned above.
> What are the odds this happens the same day they rotate their SSH keys?

Definitely a bad for them. When it rains, it pours.

brandur··on Enabling the Future of GitHub's REST API with API Versioning
I wonder if they might be amenable on that one. (If any GitHub staff is reading this.)

The proposed scheme is fairly similar to Stripe's, and although Stripe mainly uses the `Stripe-Version` header for versioning, its API has also always allowed you to alternatively send a `?_stripe_version=<version>` query parameter which it'll respect.

Stripe's API implementation definitely had its share of legacy cruft that added up and made things more difficult to maintain, but out of all of it, I don't remember having to support that alternative `_stripe_version` parameter ever really being a maintenance headache. The leading underscore made sure that even as the API expanded, it never accidentally collided with parameters on any other endpoint.

brandur··on AirDrop is now limited to 10 minutes
To be fair: (1) it seems like the update landed recently, and (2) the article you linked does cite the same reasoning as the Twitter posts. Even if was a little ahead of the more recent Zero Covid protests, it seems like AirDrop's been a known vector in China to share government criticism, which is why Apple's cracking down.
brandur··on San Francisco braces for commercial real estate crash
Linked from the article, the Urban Displacement Project's recovery ranking dashboards [1] place San Francisco dead last amongst 60 major North American cities.

[1] https://www.downtownrecovery.com/dashboards/recovery_ranking...

brandur··on Arizona Mom Fights Abusive Prosecution by Department of Child Safety
Let Grow keeps a good mythbusting page on crime stats:

https://letgrow.org/crime-statistics/

The tl;dr is that helicopter parenting is relatively new — only something that's come into play in the last few decades — and in all the time before that kids had far more freedom to roam compared to today. Even factoring in an uptick in the murder rate in the last couple years that came about during Covid policy, it's still half of what is was in the early 90s or prior to that.

It seems like the world is more dangerous now because of the outsized attention crime gets in media, but objectively speaking, it's not.

And keeping kids at home on their screens is having definite negative consequences on their maturation and later ability to succeed in the world. Here's a good article on the subject:

https://reason.com/2017/10/26/the-fragile-generation/

brandur··on Theranos former president found guilty on all fraud counts
> [2] https://stylecaster.com/sunny-balwani-net-worth/

The surprising thing to me on there was that despite the bad loans to Theranos (money that is worth $0 now), they still estimate his net worth to be $85 million as of 2022, so way up from even the $40 million he started with in the early 2000s. I guess that despite the Theranos shenanigans, most of it was parked safely.

brandur··on Theranos former president found guilty on all fraud counts
I see what you're implying, but Balwani's also been covered very extensively, including his trial.

He's featured prominently in all the most public Theranos material including the book Bad Blood and the series The Dropout. If he doesn't get as much play as Holmes it's not by much — they are both very much front and center. If you hadn't heard much about him (or the fact that he'd very much be on trial the same as Holmes), I'd very much recommend going to the source material — Carreyrou's book, which an easy 300-pager that reads like a thriller

In terms of media, try a custom Google search with a time range that excludes today's sentencing date [1] and you will find thousands of articles written about his trial before now. And beyond that, most of the articles about Holmes' trial end up talking about Balwani in the body because shifting the blame to him was her most central defensive strategy (and vice versa on Balwani's side).

---

[1] https://www.google.com/search?q=sunny+balwani&sxsrf=ALiCzsYc...

brandur··on Substack is laying off 14% of its staff
It may be true that there was a pull factor, but your comment appears to be trying to let the NYT staff off the hook for what would be considered abusive behavior in any other circumstance.

Reference, straight from the horse's mouth:

https://www.bariweiss.com/resignation-letter

Quote:

> My own forays into Wrongthink have made me the subject of constant bullying by colleagues who disagree with my views. They have called me a Nazi and a racist; I have learned to brush off comments about how I’m “writing about the Jews again.” Several colleagues perceived to be friendly with me were badgered by coworkers. My work and my character are openly demeaned on company-wide Slack channels where masthead editors regularly weigh in. There, some coworkers insist I need to be rooted out if this company is to be a truly “inclusive” one, while others post ax emojis next to my name. Still other New York Times employees publicly smear me as a liar and a bigot on Twitter with no fear that harassing me will be met with appropriate action. They never are.

This is one person's statement, but it's consistent with the way many people have written about the NYT's internal culture and internal cultural shift over the last 5-10 years.

brandur··on Can “Distraction-Free” Devices Change the Way We Write?
Fair enough.

I like the Pomera's look (and love the broad Japanese market of weird/unusual electronics), but ... I doubt I'd ever buy a device without a full-sized keyboard again. These netbook-style machines were pretty interesting back in the 90s and 00s, but they're practically impossible to type on, and we've got enough good alternatives nowadays that they don't feel worth it anymore.

brandur··on Can “Distraction-Free” Devices Change the Way We Write?
Thanks for the detailed notes! Since it was announced, I was always very enticed by the Freewriter Traveler, but never pulled the trigger because despite a couple very positive reviews, I had a haunting suspicion that it wasn't quite up to the standard of quality that I would've liked to see, and moving content in and out just seemed way too painful.

The Pomera DM200 looks really interesting — pretty sure I recognize this from a guy on my that had one (or something very close to it).

A solution I've been playing around with a lot is the a foldable keyboard (I got this one [1]) plus an iPhone. An iPhone with an external keyboard doesn't give you Cmd + Tab, which makes multi-tasking difficult by default. In addition, it has the additional advantages of:

* Leveraging a device I always have on me and which I charge every night.

* If you get the right keyboard, it's full size, keeping typing non-painful.

---

[1] https://www.amazon.com/gp/product/B018K5EJCQ/

brandur··on This real estate bubble won't pop
I would suggest reading until the end. The author makes a number of recommendations on how this outcome can possibly be avoided (see header starting with "The solution is simple" and all the way through until the end of the piece).
brandur··on COVIDSafe: Australia’s digital contact tracing failure
> There is a list of reasonable exemptions including work related travel.

Don't you think that you should've caveated your original comment with the fact that you need a specialized exemption to be able to leave?

Every other account I've read besides yours says that these exemptions are difficult and onerous to get, including for extreme cases like family emergencies. And even if you're granted one, trying to come back is still a very messy and expensive affair. As per the article's point — only available to the more privileged classes.

Here's an article from July [1] that has the numbers for June: out of 34,616 exemptions applied for, 14,522 were granted. That's about 40%.

---

[1] https://www.theguardian.com/australia-news/2021/jul/03/trave...

brandur··on Postgres: Boundless `Text` and Back Again
Yeah, you'd need a longer field for maximum correctness for sure. Reminds me of the RFC 822 regex for validating an email address [1] (clocking in at a full page, although now there are simpler ones you can use).

I tend to think that there is a point where you trade off some correctness for pragmatism. It is true that you could have a user with a 250 character email address, but in a lot of years I've never really seen a legitimate one, and the likelihood is that if you do see one then it's someone doing something weird as opposed to a legitimate customer.

Email is actually one that you might want to just leave as `TEXT` and make sure you're validating with a package, which is something you might want to do anyway. However, I still think it serves as a useful example because most people have a good feel for about how long an email address is.

---

[1] http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html

brandur··on Postgres: Boundless `Text` and Back Again
I used to recommend `CHECK` constraints as well, but was directed towards Postgres' very good intelligence around being able to relax a `VARCHAR(n)` -> `VARCHAR(>n)` as basically a no-op, so I simplified here somewhat just because VARCHARs are easier to use, and make much more succinct examples in write ups like this one.

The index rebuild is still a bit of an open question — I wouldn't be surprised if Postgres had some optimizations there as well to not need it in instances where it's not necessary, but I might be wrong on that one.

brandur··on Postgres: Boundless `Text` and Back Again
> My goodness... This has nothing to do with postures and just bad security models when programming.

Author here. Could you elaborate with some specifics?

brandur··on Postgres: Boundless `Text` and Back Again
Nice — I like the idea of the "9" convention. It serves to catch the eye (9s are positively _harsh_ compared to other numbers) and show that it's meant more as a ballpark rather than a precisely chosen number for this specific field.
brandur··on Postgres: Boundless `Text` and Back Again
I note pretty explicitly in there that you should pick your own numbers.

The idea I was trying to get across is that of order of magnitude tiers so that you don't end up with VARCHARs of a hundred random lengths.

brandur··on Postgres: Boundless `Text` and Back Again
With regards to the CHECK constraints, I actually used to recommend those because relaxing them seemed to be operationally safer, but re-reading the Postgres docs, it didn't seem like there was a particularly big advantage to them because Postgres is pretty smart changing types efficiently where possible. Is there another benefit I missed?

Interesting on the data warehouse note — we haven't actually implemented the domain idea yet (what's in the article is more musing about it), but it's good to know about this possible downside.

brandur··on Ask HN: Is there a recruiter email blocklist somewhere?
> _I don’t get many mails from recruiters. I wouldn’t invest time in setting up a block mechanism._

I think this is the most practical answer.

I get a fair number recruiter emails. The unsolicited mass messaging can be a little irking for sure, but with Gmail's hot keys, it takes ~0.1s to move an email to a special "recruiting" folder. Despite a high level of messages, I don't spend more than ten seconds on this a week, and have stopped stressing about it.

brandur··on The Idempotency-Key HTTP header field
Just to clarify: I was speaking specifically about the case where you have a series of DB calls (like: auth user, retrieve account record, insert idempotency key, do more stuff), and the first one succeeds and the next ones fail. It can happen where the DB suddenly drops out as the request is executing, but it's more likely that it's either available or it isn't, so either the request succeeds, or it can't start.

And this comment was just meant to talk about faults with your own database. Once you are reaching out to other systems you see all kinds of problems regularly, but those tend to be handled more robustly because you kind of have to.

brandur··on The Idempotency-Key HTTP header field
You might find differing philosophies depending on where you look, but a recurring theme you'll find with Stripe's is that they try to make it as easy as possible to get an integration up and running. When you're building out a payment integration, you're already awash in non-trivial concepts that are probably new and novel to you, so things that can be abstracted away for the time being to make things easier generally are.

In the situation you describe, I think it would make more sense to just retry the call a couple times from the same pod so you don't have the sizable overhead of discarding it and creating a new one for every failure, in which case the automatic keys would work fine. And if there's a really good reason they're not, setting the keys manually is very easy. At some point if you're far enough off the beaten path, you have to expect to read some docs.

brandur··on The Idempotency-Key HTTP header field
> IMHO, though, stripe should abstract away faults in banks, and figure out how to work around faults in bank's systems using e.g. automated refunds when a duplicate charge is detected, and not just bubble up a 500 to stripe's customers and leave it to them to figure out.

Yeah, this is what Stripe tries to do. Most problems during calls to foreign systems are handled in a ways that try hard not to send back an internal error. 500s are tracked carefully because they're painful to the user, but also because they leave behind potentially bad state that'll eventually cause problems internally and externally.

If they can be reconciled, a webhook will be fired to give the caller a more determinate answer (obviously less convenient for them to handle, but at least some sort of message makes its way back). More documentation on that here:

https://stripe.com/docs/error-handling#server-errors

> Transactions are not necessary if one can do an insert conditional on the key not yet existing, but then it is required to have the idempotency key from the client enter into the primary key.

This is how the implementation works more or less — an insert on a unique index that will error on a duplicate so you know it happened already. You'd probably implement it similarly in basically any major database whether Mongo, Postgres, MySQL, etc.

This is only a very small part of what transactions get you though — if a transaction-based request makes it midway through its lifecycle and then fails, it can roll back to a fresh slate. In a transaction-less system, you need to come up with some other answer for what to do what the partial state that was left behind.

← PreviousPage 2 of 11Next →