<?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 Dan Ehrman on Medium]]></title>
        <description><![CDATA[Stories by Dan Ehrman on Medium]]></description>
        <link>https://medium.com/@dan.ehrman?source=rss-b183da8938c5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*9KWfxVy6klzQacbg.</url>
            <title>Stories by Dan Ehrman on Medium</title>
            <link>https://medium.com/@dan.ehrman?source=rss-b183da8938c5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:11:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dan.ehrman/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[Fighting Adult Content with Kafka, Samza, and Google Safe Search]]></title>
            <link>https://medium.com/code-red/https-redfin-engineering-fighting-adult-content-with-kafka-samza-and-google-safe-search-ec67c381005b?source=rss-b183da8938c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec67c381005b</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Dan Ehrman]]></dc:creator>
            <pubDate>Sat, 18 Aug 2018 00:52:27 GMT</pubDate>
            <atom:updated>2019-02-25T14:13:36.040Z</atom:updated>
            <content:encoded><![CDATA[<h4>Recently, we added the ability to upload photos of your home renovations to Redfin. To get there, we faced the immediate problem of needing to maintain the integrity of our public-facing content — filtering out adult images and the like. Let’s look at how we used Kafka, Samza, and Google Safe Search to put it all together.</h4><h3>First, Why Photos?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*FEnQp0rHL8ZXiyk5V3-Wcg.png" /><figcaption>Kitchen photo uploaded by a Redfin homeowner</figcaption></figure><p>User testing showed that owners want a way to show off their homes and the hard work they’d put into recent updates. They also want a more accurate <a href="https://www.redfin.com/what-is-my-home-worth">Redfin Estimate</a>. A limiting issue we face is that we can’t see inside their homes, preventing us from fully understanding the home’s true value. With enough training data, photos may help us give a more accurate Estimate.</p><h3>System Requirements</h3><p>We had five goals in designing our photo-filtering system:</p><ol><li><strong>Accurate</strong>: the photo filter should be accurate enough to catch nearly all inappropriate content.</li><li><strong>Affordable</strong>: we should be able to validate a large volume of photos without breaking the bank.</li><li><strong>Non-blocking</strong>: homeowners should be able to upload renovation photos without waiting for them to be validated first.</li><li><strong>Handles bursts</strong>: because we’re likely to see big batches of photos from a single homeowner spread apart by long stretches of inactivity, the system should be able to handle bursts without backing up.</li><li><strong>Testable</strong>: we should be able to test the system in its entirety with photos that are accessible only from within our VPN.</li></ol><h3>Our Design</h3><p>Given the requirements, we elected to use <a href="https://kafka.apache.org/">Kafka</a> and <a href="http://samza.apache.org/">Samza</a> to meet our performance and scalability needs. We chose <a href="https://cloud.google.com/blog/products/gcp/filtering-inappropriate-content-with-the-cloud-vision-api">Google Safe Search</a> because of Google’s established reputation with computer vision, and because we’d only be charged a fraction of a cent per image. Here’s the solution we landed on:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*W5BMEZuCmlLPgDvTok49JQ.png" /></figure><ul><li>(1–3) <strong>[Non-blocking] </strong>As new photos are uploaded, mark them private so that only the uploader can see them, and complete the web request by writing photo metadata to the database.</li><li>(4) Kafka Connect, upon seeing the newly written metadata, submits requests to an asynchronous photo validation service that processes the photos.</li><li>(5) <strong>[Handles bursts] </strong>Hash the photos by ID and split the requests into different Samza containers, which each process their respective photos serially and can be scaled up to as many containers as are required for peak load.</li><li>(6) Within each container, download the image bytes from the image server.</li><li>(7) <strong>[Accurate, affordable, testable] </strong>Send the image bytes to the Google Cloud Vision Safe Search API and wait for the Safe Search annotations. (Sending image bytes rather than providing Google with an image URL enables us to test photos accessible only via our internal network.)</li><li>(8–9) Pass the Safe Search annotations to the photo writer, which records whether or not the photo passes our threshold of acceptability. Rejected photos trigger a request to a cloud-based email service, which notifies the uploader of the rejection.</li><li>(10) Later, when other clients are fetching home photos, check the database for validation results and hide any photos that did not meet our acceptability threshold.</li></ul><h3>Beta Testing</h3><p>In order to ensure that our validator was neither too aggressive nor too relaxed at filtering out inappropriate content, we inserted a manual validation phase between the validator and the writer: for every photo that Google annotated, we would send the image to a private Slack channel to be reviewed by a volunteer from our team. A simple Python script enabled us to send “block” or “allow” Kafka messages to the input of the Samza photo writer. And we enabled the feature only for a small beta group to ensure that the manual validation wasn’t too overwhelming for our volunteer.</p><p>For one month, we proceeded this way, either confirming Google’s assessment or adjusting Google’s thresholds when we disagreed. On a few occasions, bedrooms with certain kinds of blankets and color palettes were erroneously labeled adult. Elsewhere, we found that a pile of red mulch in an owner’s front yard tripped Google’s violence sensor. We iterated on our thresholds, trying to strike a balance between allowing acceptable images and catching subtly objectionable content (e.g. nudity in the reflection of a mirror), ultimately landing on a set of thresholds that we felt gave us the best of both worlds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ell_nxRs1eeTwJSZ0xnRGQ.jpeg" /><figcaption>Google’s impression of possible violent imagery</figcaption></figure><p>Once we felt confident in the auto-validation accuracy, we removed the manual validation step and made the feature available to 100% of our users. With the system fully live, photos can now be uploaded, automatically checked for objectionable content, and displayed to the public in <strong>under two seconds</strong>.</p><h3>Results</h3><p>While only a drop in the bucket compared to all owner-uploaded photos, the system <em>is</em> catching some objectionable content, proving the value of building this protection first. Here’s a recent real owner-uploaded photo, which Google correctly identified as a meme, caught by the system <em>during</em> the writing of this post:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*x2l6OQDPq_GQzjPYjf-xDw.gif" /><figcaption>Image courtesy of <a href="https://knowyourmeme.com/photos/636493-reaction-images">Know Your Meme</a></figcaption></figure><p>So we can all rest easy knowing that our technology will appropriately deny access to early ’90s movie references such as this. Ironic.</p><h3>Extensions</h3><p>After the initial deployment of our system, we added a few enhancements to improve the experience:</p><ul><li>The ability to hide listing photos from when the home last sold.</li><li>A customer service admin tool that enables our team to selectively hide or show owner-uploaded photos at owners’ request.</li><li>(Ongoing) A way to filter out not just objectionable photos but photos which have nothing to do with the associated home (e.g. a selfie, of which we get a lot…).</li></ul><h3>Parting Thoughts</h3><p>Ultimately, we’re happy with our solution. It’s scalable, accurate, and cheap. Best of all, we managed to give homeowners a tool they’d long requested without diluting our brand with bad content.</p><p>Does your product have a need for public-facing user-uploaded content—perhaps with a similar bar for quality? How did your team go about tackling this problem? Let us know in the comments below!</p><p><em>P.S. If you’d like to help us build more cool tech like this, </em><a href="https://www.redfin.com/about/jobs?utm_source=engblog"><em>we’re hiring</em></a><em>!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec67c381005b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-red/https-redfin-engineering-fighting-adult-content-with-kafka-samza-and-google-safe-search-ec67c381005b">Fighting Adult Content with Kafka, Samza, and Google Safe Search</a> was originally published in <a href="https://medium.com/code-red">Code Red</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>