Live data from Hacker News

How Discord Resizes 150M Images Every Day with Go and C++

blog.discordapp.com

101–110 of 157 posts

Re: How Discord Resizes 150M Images Every Day with Go and C++

#102
post #42

Earlier quoted context omitted.

The downvote is probably because the comment implied that the issue is that the image processing is done in "unsafe" C++ and that another language should have been used. However, there isn't much choice. Performance is very important in image processing, so much that many libraries contain hand-written assembly. In the article, it says that 90% of processing power is dedicated to it. Using a safer language in a safe…

How much does a hack of all your data and/or a major outage cost? I also recommended a mitigation strategy for unsafe code. Complaining that security is too hard is the reason for the situation we find ourselves in as an industry.

>How much does a hack of all your data and/or a major outage cost?

How much indeed ? What was the last time ? Ah, yes, Equifax. What happened ? Nothing.

Re: How Discord Resizes 150M Images Every Day with Go and C++

#103
post #91
post #61

Earlier quoted context omitted.

agree on 3) most browsers just use linear interpolation when resizing images, which makes sense from a performance point of view, but looks terrible. Better to use a bi-linear or cubic resize, more computing up front, but better images, this is probably the reason they do it

But soon you can do any type of resizing through WASM on the browser.

You can already do it, just use a library or implement your own scaling function and don't use the built-in image resize functions.

Re: How Discord Resizes 150M Images Every Day with Go and C++

#104
post #68

Earlier quoted context omitted.

I think that's a bit reductionist, no? There are many reasons they may have been searching for moving to Go. Off the top of my head I can think of: 1. Static typing increasing confidence and velocity 2. Better developer-facing tooling increasing velocity 3. More employees knowledgeable about Go than Python 4. More enthusiasm (and therefore faster velocity) around Go development. The blog post was about the engineerin…

It might be, then again I see a lot of wheel reinvention in tech / NIH syndrome. I'm the kind of hacker who if a service runs out of memory every 2 hours, writes a crontab to restart it every hour after X random minutes so they don't all restart at the same time. It gets a lot of eye rolls from the other engineers searching for perfection, but it tends to produce services quickly that are highly reliable. And look no…

I agree that tech in general and Silicon Valley in particular has a lot of NIH, but I also think this isn't really the case here. In particular, we're discussing a Python service that performs slow image resize calls. They would have (probably, speculation on my part/experience) had to do 2 things:

1. Add profiling and telemetry to their Python code. Refactor the codebase based on insights from this.

2. Write a CPython interop for their image libraries.

I can't see the cost of #2 being any different than the cost they paid on writing it in Go. As for #1, depending on how the code is structured, a rewrite may have been less time than profiling spaghetti code. At that point, it depends on how much Go experience the team has.

Re: How Discord Resizes 150M Images Every Day with Go and C++

#105

Nice, but why? https://cloudinary.com , https://www.imgix.com , or https://www.filestack.com already exist and are well worth it for 99% of apps. Even at scale, it really doesn't cost that much to have someone else do it. You can use a thin proxy through your existing CDN if you want to save on their bandwidth fees. Also http://thumbor.org and https://imageresizing.net if you want a library to host yourself which are…

I agree. Offloading this type of work to a third party who does it really well is a smart move. Why manage additional code when it's not even core to what you do?

In this case, it was perhaps cheaper for them to do in-house, and it's not rocket science? They wrote a bleeding edge library for it - sounds like they have the expertise just fine. Minimizing external dependencies can be a big deal if you have the developers to manage it.

Also, it is totally core to what they do. Images are a huge part of the Discord UX.

Re: How Discord Resizes 150M Images Every Day with Go and C++

#106

Earlier quoted context omitted.

Discord makes most of their revenue from selling user data so they probably want to keep as much as possible.

Do you have a source? That's a pretty bold claim, and I haven't seen anything else to back that up.

pretty sure they've directly stated that they're not selling user data

Re: How Discord Resizes 150M Images Every Day with Go and C++

#107

Earlier quoted context omitted.

I agree. Offloading this type of work to a third party who does it really well is a smart move. Why manage additional code when it's not even core to what you do?

In this case, it was perhaps cheaper for them to do in-house, and it's not rocket science? They wrote a bleeding edge library for it - sounds like they have the expertise just fine. Minimizing external dependencies can be a big deal if you have the developers to manage it. Also, it is totally core to what they do. Images are a huge part of the Discord UX.

At 150m images per day, not counting bandwidth, imgix would cost ~135k/month. Running 12 n1-standard-16 instances (peak load according to the article) is ~$5k/month. It's not hard to see why we wrote it in house when you consider that cost.

Re: How Discord Resizes 150M Images Every Day with Go and C++

#108

How is the security? Any sort of image processing is a potential exploitation point. I see it says it uses the 'mature' libjpeg-turbo and libpng libraries,along with giflib for .gifs, but even with full trust of those, the C code, patches, and changes ontop could be more exploitation points. You can look through Imagemagick alone to see all the fun things possible when seemingly basic processing turns into exploits.…

Wow really? Is there room for another image processing library? Is ImageMagic poorly written or is image manipulation inherently risky?

ImageMagick is notoriously questionable. It was originally written, I believe, as a local command-line tool for users to work with their own images, so security and untrusted input were not primary concerns.

Additionally, image manipulation is inherently challenging - not even due to the actual manipulation of image pixel data, but due to the proliferation of complex image container formats which require binary data manipulation and byte copying in performance-critical code. This is a minefield for secure programming practices because it puts at direct odds performance and sanity checking, as well as encouraging pointer and memory arithmetic and unsafe access.

Re: How Discord Resizes 150M Images Every Day with Go and C++

#109
post #106

Earlier quoted context omitted.

Do you have a source? That's a pretty bold claim, and I haven't seen anything else to back that up.

pretty sure they've directly stated that they're not selling user data

to be fair, you could say the same of facebook/google. they're not selling the data (giving it to third parties), but they're making money off it.
Post reply on HN