<?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[Streak Engineering Blog - Medium]]></title>
        <description><![CDATA[A blog documenting the technical journey of Streak - Medium]]></description>
        <link>https://medium.com/streak-developer-blog?source=rss----9a39be197112---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Streak Engineering Blog - Medium</title>
            <link>https://medium.com/streak-developer-blog?source=rss----9a39be197112---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 08:42:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/streak-developer-blog" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building link tracking infrastructure]]></title>
            <link>https://medium.com/streak-developer-blog/building-link-tracking-infrastructure-f6eabd80977c?source=rss----9a39be197112---4</link>
            <guid isPermaLink="false">https://medium.com/p/f6eabd80977c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[crm]]></category>
            <category><![CDATA[email-marketing]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[cloudflare]]></category>
            <dc:creator><![CDATA[Blake Kadatz]]></dc:creator>
            <pubDate>Tue, 31 May 2022 15:59:15 GMT</pubDate>
            <atom:updated>2022-05-31T17:48:29.487Z</atom:updated>
            <content:encoded><![CDATA[<p>Streak has millions of users sending many millions of emails a day through their Gmail account. Our users love the ability to track when someone has viewed emails they send, whether it’s a one-off email or when sending a mail merge. We’ve had a long-standing desire to also include click tracking of any links within the email.</p><figure><img alt="Gmail email compose window showing Streak’s link tracking toggle UI" src="https://cdn-images-1.medium.com/max/580/1*U2TW-S3W4hG6LvurtZ3raA.png" /><figcaption>Streak link tracking toggle UI within Gmail</figcaption></figure><h3>Design goals</h3><p>In building this, we had a number of goals for the link tracking functionality:</p><ol><li><strong>Must work all the time.</strong> We need to ensure that any system we implement for link tracking is highly reliable. It’s one thing for our code to have to retry a request to the API if there’s a transient issue, but our users will be sending emails to their contacts where we don’t have such control, and errors would reflect not only poorly on Streak but also on our users.</li><li><strong>Must be fast.</strong> If you’ve ever received a marketing email that has links in it, you’ve likely clicked a link and it takes forever to go to the destination because some slow CRM system is processing the click. We don’t like building slow functionality.</li><li><strong>Links must always work.</strong> Because our users are sending emails to their contacts, any tracked links in those emails should work. Forever. This means we shouldn’t tie the implementation to any one specific technology or require any database of valid links.</li><li><strong>Revocable.</strong> When a Streak users sends out any email, the email goes out through their Gmail account, which has the benefit of Google’s extensive anti-spam measures, quota enforcement, best in class deliverability, and keeping all their email in one place. However, should we need to revoke a link (for example, due to malicious use), we want to be able to prevent those specific links from working. Note that this is at odds with links always working.</li><li><strong>Spoof proof.</strong> Links must only work if they were generated by Streak. When the system generates a link, any modification of the link should render the link invalid. This prevents a malicious attacker from taking a valid link and modifying the destination to go somewhere else, or otherwise circumventing checks added during link generation.</li></ol><h3>Technology</h3><p>Since Streak runs directly within Gmail and we are a Google Technology Partner, our infrastructure runs within GCP (Google Cloud Platform).</p><p>We considered Google Cloud Run as it seemed like a cool technology where you deploy a containerized microservice and leave it up to Google to manage. Also under consideration was Google Cloud Functions which is essentially a containerless version of Cloud Run and similar to AWS Lambda.</p><figure><img alt="Cloudflare logo" src="https://cdn-images-1.medium.com/max/256/1*vjg-dv7id_MPHACxg-7nrg.png" /></figure><p>We eventually chose Cloudflare Workers to power our link tracking. Cloudflare boasts that their network reaches 95% of the world’s population within 50ms. Additionally, as they power some of the largest properties on the web we were comfortable that their infrastructure’s reliability meets or exceeds our own.</p><p>Code written for Workers runs directly in each of their edge locations, meaning we get fast distribution across more than 200 points of presence. Additionally, since the code is isolated from our existing infrastructure it’s not dependent on whichever technology stack we happen to use.</p><h3>Constructing a link specification</h3><figure><img alt="Blueprint construction plans" src="https://cdn-images-1.medium.com/max/1024/1*zRow_CZOgD-bAOVZRoNeSA.jpeg" /></figure><p>When users send emails out through Streak, our system records which links are within which emails. Then, when a recipient clicks on a link, our system associates the click with the correct email. And because Streak has millions of users sending, cumulatively, millions of emails, maintaining a copy of all that data on Cloudflare or anywhere else was a non-starter. So we needed a much simpler system.</p><p>The format of the URL that we settled on looks like this:</p><p>https://somestreakdomain.ext/uniqueidentifier/destinationurl</p><p>This consists of the following parts:</p><ol><li>The domain that we host the link on. For our links, we wanted to be completely transparent about the functionality and chose streaklinks.com for the domain.</li><li>The destination URL. Because we want the links to work regardless of platform or infrastructure, we chose a simple URL encoded version of the destination. So if you are linking to https://example.com then the encoded version is https%3A%2F%2fexample.com. While simple URL encoding does make a link easily decodable by a recipient should Streak later block the URL, the main goal is that Streak’s infrastructure isn’t directly used to link to an unwanted site.</li><li>This leaves the unique identifier. As mentioned, we use this to later associate which link in which email the recipient clicked on. At the same time, we don’t want to perform an expensive database lookup nor do we want a malicious attacker to be able to spoof arbitrary URLs in our system. The solution is that the identifier combines an identifier within Streak’s CRM with a cryptographic checksum of the data.</li></ol><p>Because the complete URL contains all the data necessary to both validate the URL and redirect the user to the destination, we don’t need to maintain any storage.</p><h3>Validating a link</h3><figure><img alt="Abstract image of display showing Matrix code" src="https://cdn-images-1.medium.com/max/640/1*bzrVk8PPFA1tejTkpEj2CQ.jpeg" /></figure><p>When a recipient clicks on a link, we extract the unique identifier and destination URL from the request. Validation is then a simple matter of performing an HMAC SHA-256 calculation of the unique identifier and the destination URL, which we use to ensure the integrity and authenticity of the link.</p><p>Cloudflare has some docs on Web Crypto at <a href="https://developers.cloudflare.com/workers/runtime-apis/web-crypto/">https://developers.cloudflare.com/workers/runtime-apis/web-crypto/</a> which outlines how to calculate a message digest. In our case, this looks something like this:</p><pre>const encoder = new TextEncoder();<br>const secretKeyData = encoder.encode(SECRET_KEY);<br>const key = await crypto.subtle.importKey(<br>  &#39;raw&#39;,<br>  secretKeyData,<br>  {name: &#39;HMAC&#39;, hash: &#39;SHA-256&#39;},<br>  false,<br>  [&#39;sign&#39;]<br>);<br>const mac = await crypto.subtle.sign(&#39;HMAC&#39;, key, encoder.encode(message));</pre><p>In the above code, SECRET_KEY is a secret that has been set via wrangler:</p><pre>wrangler secret put SECRET_KEY</pre><p>The value of this secret key is shared between Cloudflare and our API code which generated the link in the first place. The mac (Message Authentication Code) value contains an ArrayBuffer with the bytes, which we extract and use to verify that the link was generated by our API without having to contact the API or lookup any data.</p><p>Additionally, we store a blocklist of undesirable links in Cloudflare Workers KV (a key/value store) and we verify that the link has not been blocklisted. Workers makes this quite simple. In our case, we created a new KV namespace like blocklisted-links and then bound it to the worker using the name BLOCKLIST. To check if a destination URL is on the blocklist, it’s simply:</p><pre>const MAX_KEY_LENGTH = 512;<br>const blocklistKey = (&#39;url:&#39; + destinationUrl).substring(0, MAX_KEY_LENGTH);<br>const blocklistEntry = await BLOCKLIST.get(blocklistKey);</pre><p>If blocklistEntry is anything other than null, that means we’ve blocklisted the URL and we can reject the request. Note the use of the url: prefix here for checking the full URL. This allows us to use various prefixes to expand the blocklist to support any kind of blocking, whether via hostname, ip address, user-agent, and so on.</p><p>If everything checks out, the Cloudflare Worker code immediately redirects the user to the destination:</p><pre>return new Response(&#39;&#39;, {<br>  status: 302,<br>  headers: {<br>    location: destinationUrl<br>  }<br>});</pre><h3>Overall request flow</h3><figure><img alt="Flowchart visualizing description of request flow" src="https://cdn-images-1.medium.com/max/745/1*LtdywLOxVwkSLiHBBwjTHA.png" /></figure><h3>Fast performance</h3><p>The Cloudflare Worker code redirects requests to the destination URL in single digit milliseconds. Real world performance testing shows that link redirection can occur in approximately 20ms including making the request, processing the request inside the Cloudflare Worker code, and sending the redirection response. Most requests are so quick that the browser does not have time to display the streaklinks.com domain before the request to the destination occurs.</p><p>Behind the scenes, we take advantage of the fact that inside a Worker, fetch events (see <a href="https://developers.cloudflare.com/workers/runtime-apis/fetch-event/">https://developers.cloudflare.com/workers/runtime-apis/fetch-event/</a>) run asynchronously and live beyond the lifecycle of the user request. While the email recipient’s click has already been redirected to their destination, the Worker code pushes the click data to our system where we update the Streak user’s CRM data:</p><pre>event.waitUntil(postToStreak(data));</pre><p>We run this code just prior to returning the redirection response. Here, data is an object that contains information about the request including unique ID, destination, timestamp, and so on. When processed, our API associates this data with the original sent email.</p><h3>Launching link tracking</h3><p>Soon after we launched, we saw some incredible success with the system. Cloudflare’s performance excelled at our goal of having very fast redirection and handled a massive number of requests:</p><figure><img alt="Graph of Cloudflare Worker performance showing 986K requests, duration of 10.8k GB-sec, and median CPU time of 1.5 ms" src="https://cdn-images-1.medium.com/max/1024/1*-Zd6G7dIR4GdCTD6GwOINw.png" /></figure><h3>Geeking out on logs</h3><p>Cloudflare lets you easily live stream requests using <a href="https://developers.cloudflare.com/workers/cli-wrangler/commands/#tail">wrangler</a>. A simple wrangler tail -f pretty from the terminal and requests flood in, including any console logging performed within the worker.</p><pre>console.error(&#39;Something went wrong!&#39;);<br>console.debug(&#39;Everything is good&#39;);</pre><p>See <a href="https://developers.cloudflare.com/workers/learning/logging-workers/">https://developers.cloudflare.com/workers/learning/logging-workers/</a> for details. During development, this was invaluable to quickly verify details of the request and response. And once rolled out to production, streaming only errors caught a few issues where we weren’t gracefully handling invalid requests. And, when we want to see everything, we stream the debug logs as well.</p><p>In examining the logs, there were a few interesting things to note:</p><ol><li>Browsers, of course, attempt to fetch a favicon.ico file. We didn’t plan to serve one initially, but it was an easy matter of serving up Streak’s favicon directly from the Worker. Similarly for people who are curious about what <a href="http://streaklinks.com/">streaklinks.com</a> is all about, when they visit <a href="https://streaklinks.com/">https://streaklinks.com/</a> we redirect them to <a href="https://www.streak.com/">https://www.streak.com/</a></li><li>Anyone who has run any internet-facing system is familiar with automated exploit attempts. Soon after the domain went live, we saw all manner of malicious traffic. Fortunately, Cloudflare doesn’t break a sweat with all those requests and the Worker code trivially rejects invalid requests without effort.</li></ol><p>As part of our commitment to overall security, we allow ethical hackers to try and discover vulnerabilities our systems via Hacker One and link tracking is fair game. More information at <a href="https://www.streak.com/security">https://www.streak.com/security</a></p><h3>Wrapping it up</h3><p>Exploring the benefits that Cloudflare has to offer has been fun. With the new feature successfully launched to everyone, Streak users now get additional valuable insights into how recipients are interacting with their emails without having to use third party tools or leave Gmail.</p><figure><img alt="Gmail email compose window showing Streak’s link tracking toggle UI" src="https://cdn-images-1.medium.com/max/580/1*U2TW-S3W4hG6LvurtZ3raA.png" /></figure><p>Cloudflare Workers has proven to be extremely reliable and fast and our link tracking functionality has operated flawlessly. Having proven the benefits of Cloudflare Workers as part of our engineering toolkit, we now have a reference on how to build out fast, reliable functionality that integrates with our existing infrastructure.</p><h3>Engineering at Streak</h3><p>We work on many interesting challenges affecting millions of users and many terabytes of data. For more information, visit <a href="https://www.streak.com/careers">https://www.streak.com/careers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6eabd80977c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streak-developer-blog/building-link-tracking-infrastructure-f6eabd80977c">Building link tracking infrastructure</a> was originally published in <a href="https://medium.com/streak-developer-blog">Streak Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[We’re proud to announce that Streak has been named Google’s G Suite Technology Partner of the Year!]]></title>
            <link>https://medium.com/streak-developer-blog/were-proud-to-announce-that-streak-has-been-named-google-s-g-suite-technology-partner-of-the-year-c1733bee5e6e?source=rss----9a39be197112---4</link>
            <guid isPermaLink="false">https://medium.com/p/c1733bee5e6e</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[g-suite]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Fred Wulff]]></dc:creator>
            <pubDate>Wed, 10 Apr 2019 22:52:43 GMT</pubDate>
            <atom:updated>2019-04-10T22:52:43.777Z</atom:updated>
            <content:encoded><![CDATA[<p>In addition to being an endorsement of our product’s innovation and utilization of Google’s services, this award is a testament to the excellent work our team has been doing to push G Suite and the Google Cloud Platform further and faster for the last several years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*NIxVhax9bW5Fs5hOv3ZXiA.png" /></figure><p>Building Streak has always presented us with unique, hard-to-solve, engineering challenges. These kinds of challenges are why we keep building: doing the hard work today — whether that’s beta-testing the latest Google API or finding novel ways to use existing ones — sets us up for success tomorrow. We believe in sharing our solutions to these challenges, too, because we know it improves both our product and the developer community more broadly.</p><p>Just over the last year, our developers made sure <a href="https://www.inboxsdk.com/"><strong>InboxSDK</strong></a> and the millions of users that rely on it were ready for the massive changes to interface and functionality of the <a href="https://support.google.com/a/answer/7684334?hl=en">new material Gmail</a>.</p><p>We also developed <a href="https://github.com/StreakYC/Ratchet"><strong>Ratchet</strong></a>, the first Java data-modeling library for Cloud Spanner to interface with our database — the largest of its kind in Spanner. Streak uses it to decrease the time required to create Spanner-powered features and to ensure that everybody on the team is working with a consistent view of the data model. We’re excited to share it with the open source community and look forward to helping enlarge the Spanner ecosystem.</p><p>Our roadmap for the next year is full of equally challenging problems. We’re investing heavily in optimizing our Google Cloud infrastructure, building a graph database on top of Cloud Spanner and Cloud Bigtable, and applying machine learning on top of our massive dataset.</p><p>If you’re interested in working with our international team on those problems, check out our <a href="http://www.streak.com/careers">careers page</a> — we’d love to solve them with you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1733bee5e6e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streak-developer-blog/were-proud-to-announce-that-streak-has-been-named-google-s-g-suite-technology-partner-of-the-year-c1733bee5e6e">We’re proud to announce that Streak has been named Google’s G Suite Technology Partner of the Year!</a> was originally published in <a href="https://medium.com/streak-developer-blog">Streak Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Cheat Sheet I Wish I had before Building our Zapier Integration]]></title>
            <link>https://medium.com/streak-developer-blog/the-cheat-sheet-i-wish-i-had-before-building-our-zapier-integration-c3336bda264e?source=rss----9a39be197112---4</link>
            <guid isPermaLink="false">https://medium.com/p/c3336bda264e</guid>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[beginner-javascript]]></category>
            <dc:creator><![CDATA[Becca Saines]]></dc:creator>
            <pubDate>Wed, 24 Jan 2018 18:10:54 GMT</pubDate>
            <atom:updated>2018-01-25T01:18:11.330Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine explaining how to use Instagram to your 30-something’s co-worker. Now imagine explaining Instagram to your 80-something’s grandmother.</p><p>Documentation is mission critical to the success of a new developer product, but finding the sweet spot for maximizing audience engagement is no trivial task. Lucky for you, my loss (of time) is your gain. I hope this blog post will save you a ton of time, effort, and that you’ll be building on this reliably awesome tool faster than grandma can say “Snapchat”.</p><h3>Vocabulary</h3><p>First off, the <a href="https://zapier.com/developer/documentation/v2/">Zapier docs</a> do not have a dedicated glossary of keywords and terms. You can get the gist from their individual category sections, but having a dedicated reference list certainly would have softened the slope of my own learning curve.</p><p>Another benefit of a dedicated glossary is being able to compare the keyword definitions for developers and non-technical end-users side by side. The Zapier documentation does do this to an extent (hats off, Zapier!) but still assumes a level of knowledge above what I had as a <a href="https://zapier.com/developer/">developer just beginning to work on Zapier</a>.</p><h3>App</h3><ul><li><em>End User Definition</em> — The singular and only way to ever interact with your company’s data/API/integration.</li><li><em>Developer Definition</em> — The current version of the code/scripting you’re working on. An app may be public, private, or invite only, but scripting for public/invite only apps can only be updated through a deploy of private apps. You are going to have a lot of private apps and that’s OK.</li></ul><h3>Action</h3><ul><li><em>End User Definition </em>— The thing that automagically happens after the trigger occurs.</li><li><em>Developer Definition</em> — The `POST` request (body comes from the Action Fields) made to the url I specify (<strong>Note</strong>: I am considering actions very separate from ‘Searches’ or other Zapier features that transform data mid-Zap).</li></ul><h4>Action Field</h4><ul><li>As a new developer to Zapier, this term took me an inexplicably long time to comprehend, perhaps because there are so many places in the Zapier documentation where “Action Field” is described, used, defined, and expanded on.</li><li>An Action Field is an input field for the user while they’re creating their Zap. It makes sense if you break down the words — it’s a field (that the user fills in) on the user-facing action part of a Zap. An Action Field represents the value of a key that becomes input to your scripting. Action Fields get passed as the body of the POST request made to your API endpoint when a Zap runs.</li></ul><h4>Parts of an Action</h4><ul><li><strong>Name: </strong>Not used in scripting. User-facing value for the way they identify an action available through your app.</li><li><strong>Noun: </strong>Not used in scripting. User-facing value for the object they’re working to create/update.</li><li><strong>Key: </strong>Used in scripting! Used as a prefix to identify this action in code.</li><li><strong>Help Text: </strong>Not used in scripting. Help text that the user will never read, because users rarely read anything, but Zapier still requires.</li></ul><h3>Trigger</h3><ul><li><em>End User Definition</em> — The event that starts my Zap.</li><li><em>Developer Definition</em> — Whether by polling or webhook, Zapier ends up with a JSON object to splice up. Values from specific keys of this object will be sent to the next step of the zap.</li></ul><h4>Trigger Fields</h4><ul><li>Much like Action Fields, these are the fields available on the user-facing Trigger setup for user input. Unlike the previously described action, the trigger fields are used for filtering / determining if a Zap should continue.</li></ul><h4>Parts of a Trigger</h4><ul><li>Use the same definitions found for Name, Noun, Key, and Description as described above for actions.</li><li><strong>Bundle: </strong>The bundle is only ever referenced in the context of scripting — this is purely a developer-side keyword. The bundle is the object that is being updated; some of the data in the bundle might be sent as values to other API endpoints. The bundle contains headers for the request Zapier makes to any API endpoint you specify in your app, including any Auth information. Knowing where this Auth information lives is particularly useful if you’d like to make an additional request as part of your scripting logic.</li></ul><h3>Draw me a picture</h3><p>In general, I feel there is a lack of pictures in technical documentation. I understand the reason for this — pictures are not easily updated, and even more so than text, should be geared towards a specific audience. However, I find them obscenely useful for getting a big picture context when I’m starting to learn something, so here is my (crude) picture of how Zapier works, specifically geared towards beginners:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H9WQxAX1JQXXR_s1." /><figcaption>Zapier Sushi</figcaption></figure><h3>Printing and Logs</h3><h4>Console.log()</h4><p>You’re working on your scripting and you’d like to print something to confirm your suspicions and advance your code. How do you do this? Where does it print?</p><p><strong>Step 1:</strong> Open the Scripting for your app.</p><p><strong>Step 2:</strong> Under Quick links (top right corner), click on Bundle Logs</p><p><strong>Step 3:</strong> The bundle logs are divided up by the functions that ran and a section for “The logs”. This is where you’ll find anything you’ve console.log()-ed.</p><p>Check out this <a href="https://cl.ly/263H121s2L2x">sweet gif</a> to see these steps in action!</p><h4>Task History</h4><p>The Bundle Logs (described above) will show you errors and are most useful while you’re working on the scripting portion of your Zapier app. However, they’re not great for getting a bird’s-eye view of a Zap that involves another app or even one of your own apps that is public.</p><p>For your first stop when debugging a Zap you’ve created (remember debugging a Zap is distinct from debugging your scripting), I suggest visiting the Task History. This will give you the `data in` and the `data out` for each step, even for steps belonging to different apps. The Task History will even give you some error messages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UjG_9RxQEzs35rpT." /></figure><p><a href="https://cl.ly/0h0S0H3X2w1V">Check this out</a> if you prefer your information in video format.</p><h4>Inspecting a Single Request</h4><p>Basically Task History (described above) but with more detail. If you’d like to see the headers, the method, the request url, or the response content while debugging a Zap, this is the tool for you.</p><p><strong>Step 1:</strong> From your app, find the category for the Request Log.</p><p><strong>Step 2:</strong> Click on the original viewer.</p><p><strong>Step 3: </strong>On the far right, click the buttons for More Details.</p><p><strong>Step 4:</strong> Profit.</p><p><strong>A note about the Original Viewer vs the New Log Viewer: </strong>You have two options for your log-viewing-pleasure in Zapier. The two viewers are very similar, but the new one has more options for you to filter on. At first I was partial to the Original Viewer but as time has gone on I’ve come to appreciate the diminished scrolling of the New Viewer. Examples of both the original and the new log viewers are below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B9uRmew4QXw3kM6-." /><figcaption>Original Viewer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6C2Y0LVGo6g4x-ov." /><figcaption>New Log Viewer</figcaption></figure><p>Check out how to access the Original Viewer through the <a href="https://cl.ly/1l2q0i3Y3P3k">power of gif</a>.</p><h3>Super Important “Gotchas” that will save you oodles of time</h3><ul><li>If you use console.log() with anything too large, any logs prior will not show — only the logs after will appear.</li><li>You can return an empty array to stop a Zap (instead of throwing an error, which might potentially pause the Zap for the user if the error is thrown too many times).</li><li>Datetime: Zapier’s standard datetime format is an ISO-8601 formatted string. This means that if you receive a date from Zapier for a user’s action and your API expects a UNIX timestamp, you’ll need to use moment.js (thankfully a library Zapier Scripting allows access to) or `new Date()` to convert it via scripting before passing it to your API.</li><li>You can access information in the user’s Zapier profile via scripting! For instance, `bundle.zap.user.timezone`will give you the timezone the user entered on their Zapier profile.</li><li>Pre’s and Posts in Scripting: There are a lot of suffixes you can put on a key (that’s the thing from the trigger or the action that identifies which action/trigger you’re scripting about) — pre_poll, pre_read_resource, post_search, pre_write, etc. The myriad of options were really overwhelming for me when I first started developing features on our Zapier app. I wish someone has summed it up like this: pre_stuff is for before Zapier makes the request to your API. As a result, it’s mainly going to be used for things like adjusting the request url, or the headers of the request. The post_stuff is used after the request for data has been made, and so is mainly for adjusting the data you receive in the response to the request.</li></ul><p><a href="https://zapier.com/apps/streak/integrations/">Streak’s integration with Zapier</a> has enabled our users of varying technical capacity to really make the most out of our API. It’s been a fantastic tool to engage and create efficiency for our users through automation, and it’s all taken care of in a user-facing UI that’s friendlier than a border collie. A further plus is that Zapier’s support — both for developers and users — is top notch. I’ve been impressed with both the speed and quality of the support they consistently offer. As with any new technology tool, the learning tool can be steep. But the good news with Zapier is that you’re not going it alone.</p><p><a href="https://news.ycombinator.com/item?id=16224868"><em>Discuss on HN</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3336bda264e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streak-developer-blog/the-cheat-sheet-i-wish-i-had-before-building-our-zapier-integration-c3336bda264e">The Cheat Sheet I Wish I had before Building our Zapier Integration</a> was originally published in <a href="https://medium.com/streak-developer-blog">Streak Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Powering Streak’s Gmail Add-on: Part 1 — Backing into GraphQL]]></title>
            <link>https://medium.com/streak-developer-blog/powering-streaks-gmail-add-on-part-1-backing-into-graphql-1546be75c78?source=rss----9a39be197112---4</link>
            <guid isPermaLink="false">https://medium.com/p/1546be75c78</guid>
            <category><![CDATA[g-suite]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[gmail]]></category>
            <dc:creator><![CDATA[Fred Wulff]]></dc:creator>
            <pubDate>Wed, 27 Dec 2017 03:16:54 GMT</pubDate>
            <atom:updated>2017-12-27T03:16:54.502Z</atom:updated>
            <content:encoded><![CDATA[<p>At <a href="https://www.streak.com/">Streak</a>, we recently partnered with Google to release our <a href="https://www.blog.google/products/g-suite/do-more-your-inbox-gmail-add-ons/">Gmail Add-on</a> as part of the Add-ons launch. The Add-on is our first major foray into integrating with your existing mobile apps: it lets you better organize your work email in the mobile Gmail app, and makes it easier to collaborate with your team to make sure nothing slips through the cracks. The reception has been great. Our Add-on is top rated in the <a href="https://gsuite.google.com/marketplace/app/streak_crm_addon_for_gmail/800057673271">Marketplace</a> and tens of thousands of users interact with it regularly. But the backend of the Add-on is also new: it’s 100% powered by <a href="http://graphql.org/">GraphQL</a>, albeit in an unusual way, and I wanted to share the engineering story of how we got here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/0*PXAYtcldghrBnjUU." /><figcaption>The Streak Gmail Add-On on Android</figcaption></figure><h3>A Performance Problem</h3><p>Our GraphQL journey started with us staring at a loading spinner. The fundamental purpose of our Gmail Add-on is to give the user more context about their emails. Useful context comes in many forms. If you’ve told Streak that an email is part of a sales deal, then we should add information about that deal when you view the email. If the customer you’re talking to is also talking to somebody else on your support team about an issue, you probably want to know that. And if the customer’s trial is going to run out today and might need to be extended, that’s important, too.</p><p>Surfacing all this context is the core of our user experience, but the information lives in a lot of different places, so displaying it requires querying a bunch of different API endpoints: pipelines, contacts, deals, other emails, and organizations just to start. Our main Javascript client pipelines these queries using parallel, asynchronous requests against our REST API, making sure that we’re pulling contacts at the same time as organizations at the same time as the deal information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/0*-5H7c9VhxDKwQPro." /><figcaption>Some of the many parallel requests fetching one box using the web client</figcaption></figure><p>This was where we hit our first Add-ons roadblock. Google <a href="https://developers.google.com/apps-script/">Apps Script</a>, which powers Add-ons, is a hosted Javascript sandbox environment with some non-standard APIs. Instead of the traditional XHR interface, requests to backends are required to use a custom URLFetch service. And URLFetch only allows blocking requests. Requesting all the data serially could take tens of seconds. <strong>Ain’t nobody got time for that.</strong></p><p>We realized that to get acceptable performance, we needed to combine the requests. Instead of getting “/email/15fb6cb3b627304f” followed by getting “/contacts/15fb6cb3b627304f”, we needed one endpoint: “/emails+contacts/15fb6cb3b627304f”. We spent a while manually bundling handlers together, but it turns out nobody on our team wanted to pick up artisanally hand-crafting batch endpoints as a long-term hobby.</p><p>Griping about it at lunch one day, one of our frontend developers suggested GraphQL. GraphQL bundles a lot of functionality that’s useful for making flexible APIs in a query language and a simple HTTP protocol. And relevant to our interests, GraphQL lets you request multiple objects in one go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lkFR-Sm1Xsr11Ym__qsJYw.png" /><figcaption>A single GraphQL query fetching multiple objects</figcaption></figure><p>It also provides functionality for introspecting response schemas, only fetching portions of a response (to save bandwidth costs), and for eagerly requesting related objects (e.g. following foreign keys to their object). This is very powerful, but in the context of a user-facing API, also a little scary. Some of our teams have hundreds of thousands of deals. What if somebody requested all of them <em>and</em> their related information in one go?</p><p>So we decided to take a measured approach to GraphQL, using it only for communication between our Add-on running in the Apps Script sandbox and our backend to start.</p><h3>GraphQL Implementation Strategies</h3><p>There are two main models for retrofitting GraphQL onto a RESTful API backend. The first adds a proxy layer in front of the existing server, typically in Node since that runtime has the original GraphQL backend server. The proxy translates the GraphQL query into traditional API requests, sends them in parallel, and constructs the GraphQL response.</p><p>The second model adds a GraphQL endpoint directly on our backend server, using the <a href="https://github.com/graphql-java/graphql-java">graphql-java</a> library. This endpoint either programmatically requests information from the existing endpoints, or does the same work they do to fetch the data from our backend datastore.</p><p>The main arguments in favor of the proxy approach was that it was completely separated from our existing stack. Our existing endpoints were well-tested, we were confident that we knew how to monitor them, and we knew that they correctly enforced permissions.</p><p>The main arguments for the integrated approach center around development and runtime efficiency:</p><ul><li>Thinking about development time, our existing API uses <a href="https://github.com/google/gson">GSON</a> to serialize data model objects into responses. By reusing the annotation and type information from GSON, we don’t have to duplicate our data model schema when creating our GraphQL endpoints.</li><li>Then at runtime, many of our existing API endpoints have to fetch multiple objects in order to provide their results. For instance, when fetching a contact, we also have to fetch the team that contact belongs to in order to make sure the current user has permission to view the contact. If a GraphQL query wants both the contact <strong>and</strong> its team, we shouldn’t need to fetch the team once for the GraphQL query and then again to check permissions for the contact.</li></ul><h3>Initial Results</h3><p>Since our whole purpose of using GraphQL was to make our Add-ons more efficient, we decided to pursue the integrated option. After some fun with Maven and getting Java 8 deployed on App Engine, we got a proof of concept working.</p><p>The good news: requests were batched and the request took about half as long as the previous serial requests.</p><p>The bad news: half as long as the previous serial requests was still roughly six seconds longer than we were looking for.</p><p>Hopeful but with a ways to go, we dove into the exciting world of GraphQL layering and instrumentation to track down the lingering performance issues.</p><p><em>We’ll talk more about our GraphQL experience next week, and in future blog posts delve into the build infrastructure we developed to build the Add-on itself and how we used </em><a href="https://cloud.google.com/spanner/"><em>Google Cloud Spanner</em></a><em> to enhance our backend performance.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1546be75c78" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streak-developer-blog/powering-streaks-gmail-add-on-part-1-backing-into-graphql-1546be75c78">Powering Streak’s Gmail Add-on: Part 1 — Backing into GraphQL</a> was originally published in <a href="https://medium.com/streak-developer-blog">Streak Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Complexities of Implementing Inline Autocomplete for Content Editables]]></title>
            <link>https://medium.com/streak-developer-blog/the-complexities-of-implementing-inline-autocomplete-for-content-editables-e358c0ed504b?source=rss----9a39be197112---4</link>
            <guid isPermaLink="false">https://medium.com/p/e358c0ed504b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[contenteditable]]></category>
            <category><![CDATA[gmail]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Omar Ismail]]></dc:creator>
            <pubDate>Tue, 19 Dec 2017 18:29:47 GMT</pubDate>
            <atom:updated>2017-12-19T18:32:23.928Z</atom:updated>
            <content:encoded><![CDATA[<p>When we recently rebuilt our MailMerge feature (<a href="https://blog.streak.com/brand-new-mail-merge-d8f454b65a93">announcement post</a>) we ran into an interesting challenge to implement an inline autocomplete. Our MailMerge feature lets users write a templated email and merge that with their Streak CRM data. That is, users can send emails to multiple recipients and Streak will customize each one based on the variables they insert into the template.</p><p>For better variable discovery and easier variable insertion we decided to go with an inline autocomplete like you see on popular services such as Twitter, Facebook, Slack or Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*uF_WVLYDblwtSrN_lWW24w.png" /><figcaption>The UI we were looking to build</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sBcY_Gc_RxGhGkld." /><figcaption>Twitter autocomplete</figcaption></figure><p>Since this inline autocomplete behavior exists in many other services we figured there would be a wealth of popular libraries to choose from. For our purposes we had two main requirements (more details on each found below):</p><ol><li>Uses native DOM events</li><li>Allows us to use our existing menu components</li></ol><h4>Uses Native DOM Events</h4><p>Native DOM events allow us to use the same library when enhancing Gmail’s compose body (a standard contenteditable) and within Streak’s own React-based input components. This has multiple benefits:</p><ol><li>Keeps code size small</li><li>Easier to maintain when we want to update behavior</li><li>Provides a consistent experience for our users. There can be subtle quirks around arrow handling and escape handling that can differ between libraries</li></ol><h4>Use our existing menu components</h4><p>As part of the autocomplete UI there is a menu that pops up with suggestions. Streak already has a plethora of menus in its UI that arebuilt with our fantastic <a href="https://github.com/StreakYC/react-menu-list">React Menu List</a> library. For the re-use benefits listed above we wanted the autocomplete library to be able to decouple the menu rendering from its other responsibilities.</p><h3>The Search for an Existing Solution</h3><p>Pretty much every library we found relied on something other than the native DOM (jQuery, React or Bootstrap) except for one, <a href="https://zurb.com/playground/tribute">TributeJS</a>. If you’re ok with a fully React solution then <a href="https://github.com/effektif/react-mentions">React Mentions</a> and <a href="https://github.com/mattkrick/react-githubish-mentions">React Githubish Mentions</a> both look good.</p><h4>Tribute.js</h4><p>Tribute has a nice API where you can attach a tribute instance to an existing input to magically add the mention capabilities and it uses native DOM events! Sweet!</p><p>However, Tribute doesn’t support the 2nd requirement of being able to use our own components as it handles rendering the menu and menu contents entirely itself. It does offer a “menuItemTemplate” option but that expects a string in return which you then have to be careful with your escaping so you don’t open yourself up to XSS attacks. Also, our in-house React MenuItem components expect to be housed in our Menu container component so using <em>ReactDOM.renderToStaticMarkup()</em> doesn’t work.</p><p>At this point we figured it would be better to try to enhance the existing Tribute library rather than go off and write our own. However, after we started digging into the source we found 2 things that moved us to build an in-house solution:</p><ol><li>There were some serious bugs (<a href="https://github.com/zurb/tribute/issues/69">memory leak</a>) that we couldn’t figure out how to fix, and</li><li>Implementing an in-house solution with ideas from Tributejs would allow us to leverage a lot of our existing libraries keeping code much smaller</li></ol><h3>In-House Solution</h3><p>After digging around the Tribute source we found that powering an @mention in an input comes down to 5 different tasks.</p><ol><li>Monitor the cursor position</li><li>Get the text around the cursor</li><li>Check for potential matches</li><li>If there are matches then render <em>something</em> at the cursor position</li><li>If the user picks an autocomplete item then replace the typed in text with the replacement text</li></ol><h4>Monitor the cursor position</h4><p>You need to listen to the different events that can change the cursor position: ‘keyup’, ‘input’, ‘click’, and ‘focus’. We use <a href="https://kefirjs.github.io/kefir/">Kefir</a> so listening to, merging, and debouncing all those events is straightforward.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1edb2c98138f30ab0204778420ade5b/href">https://medium.com/media/c1edb2c98138f30ab0204778420ade5b/href</a></iframe><h4>Get the Text Around the Cursor</h4><p>We need the text around the cursor so we can construct a query to check for potential matches. To do this we get the text node that the cursor is currently located in, get the parent, then call normalize (<a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/normalize">MDN docs</a>) on the parent. We call normalize because the parent node can contain multiple text nodes that are siblings to one another. To the user all the text looks contiguous, but at the DOM level if we want to get the text that is before/after the cursor we need to manually join the content from these sibling text nodes. By calling normalize on the parent all the text nodes get collapsed into one and we don’t need to deal with any of that. After normalizing we get the text node again (since it could have changed after normalize) and some other convenient data like the character position of the cursor and the text before and after the cursor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c18607cfab977f9af82304601e172518/href">https://medium.com/media/c18607cfab977f9af82304601e172518/href</a></iframe><h4>Check for Potential Matches</h4><p>Once you have your cursor position and the text around your cursor what do you use as the query when triggering the autocomplete search? we made the choice that we would only consider the text within the same text node as the cursor. This means that new lines, phrases with different formatting (a bolded section of the text) would act as natural boundary markers.</p><p>After that we chose a straightforward algorithm that looks back from your cursor position one character at a time, with each iteration checking if there are any matches. You stop iterating as soon as you have some matches or you exhaust all the characters.</p><h4>Render Something at the Cursor Position</h4><p>Once we have the set of results we have to translate the current cursor position into pixel coordinates in order to render the menu. Tributejs solved this by inserting a marker element at the cursor position, using <em>getBoundingClientRect()</em> to get the marker position, and then removing the marker element (<a href="https://github.com/zurb/tribute/blob/master/src/TributeRange.js#L436">see their implementation</a>).</p><p>I ended up implementing a similar technique, however we used another great library we have, <a href="https://github.com/AgentME/contain-by-screen">contain-by-screen</a>, that takes a fixed position element and positions it relative to an anchor element, including handling all the annoying edge cases (pun intended).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0081639681b77c94df7646ad0249976d/href">https://medium.com/media/0081639681b77c94df7646ad0249976d/href</a></iframe><p>You may have noticed that the last line of the gist we call normalize on textNodeParent. We do this because inserting the marker element splits the text node into two text nodes, so calling normalize repairs this split.</p><h4>Replace Query Text On Selection</h4><p>Once the user selects one of the suggestions we then need to replace the text the user has typed with the replacement text. The first two lines of the function are doing the actual replacement, with the rest of the function placing the cursor just after the replacement text.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/300f834c529cd3b852c518afce2a8932/href">https://medium.com/media/300f834c529cd3b852c518afce2a8932/href</a></iframe><h3>Final Result</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/0*dr5lH7CeoJcxwmVM." /></figure><p>This solution meets both of our main requirements and even allows us to use our other existing libraries like containByScreen and Kefir. The autocomplete specific code is only around 100 lines which you can easily incorporate into your own projects no matter what technology you use.</p><p>If you like working on these kind of problems then check out our <a href="https://www.streak.com/careers">careers</a> page as we’re always hiring great people!</p><p><a href="https://news.ycombinator.com/item?id=15962598">Discuss on HN</a>.</p><p>Thanks to Sean McBride, Aleem Mawani, Fred Wulff, Becca Saines, Henry Walton, Erik Munson and John Wells for reading and editing drafts of this post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e358c0ed504b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streak-developer-blog/the-complexities-of-implementing-inline-autocomplete-for-content-editables-e358c0ed504b">The Complexities of Implementing Inline Autocomplete for Content Editables</a> was originally published in <a href="https://medium.com/streak-developer-blog">Streak Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Export Your Google App Engine Logs to BigQuery: Introducing Mache]]></title>
            <link>https://medium.com/streak-developer-blog/export-your-google-app-engine-logs-to-bigquery-introducing-mache-5dee7db9547?source=rss----9a39be197112---4</link>
            <guid isPermaLink="false">https://medium.com/p/5dee7db9547</guid>
            <category><![CDATA[streaks]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Aleem Mawani]]></dc:creator>
            <pubDate>Tue, 12 Dec 2017 19:57:18 GMT</pubDate>
            <atom:updated>2017-12-12T19:57:17.565Z</atom:updated>
            <content:encoded><![CDATA[<p>Here at <a href="http://www.streak.com/">Streak</a> we know that our users’ inboxes are central to their day, and we’re honored that they let us help organize their email. But with great placement comes great responsibility: if Streak doesn’t function perfectly, it’s front and center. To ensure that we catch any errors as soon as possible, like all good webapps, we keep track of any errors that occur either on our servers or in our users’ inboxes. Additionally, we gather a number of anonymous metrics that help us decide where to focus our efforts on improving the product.</p><p>We’ve been using Google App Engine’s built-in logging framework for this purpose. It’s worked very well for diagnosing errors as they happened, but we also want to get a higher level overview of the information we’re logging. We want to answer questions like:</p><ul><li>How often do people access their Streak pipelines?</li><li>Is the newest client version fixing the error our Belgian users were encountering?</li></ul><p>We’d also like to look further back in time: did that work we did improve our latency today compared to last Friday? Luckily, Google recently released the BigQuery API for just this kind of high level, big data processing. As soon as we saw it, we knew we wanted to use it to figure out where we could best help our users. We just needed a way to export our App Engine logs to BigQuery for processing.</p><p>In the grand tradition of scratching our own itch, we’ve been working on a way to do just that. We’ve been pleased with the results so far, and we’re hoping that other App Engine users in the same boat will find it similarly compelling.</p><p>We’re proud to announce <strong>Mache</strong>, an open source Java framework for exporting App Engine logs to BigQuery. It’s available at: <a href="http://github.com/StreakYC/mache">http://github.com/StreakYC/mache</a></p><p>Mache is powered by a cron job that runs every few minutes. It exports logs to Google Cloud Storage, where you can store them indefinitely, and then initiates the job to import the logs to BigQuery. It’s extensible: you can define your own log parsers, choose how often to export the logs, and decide how to aggregate them into BigQuery tables.</p><h4>An example run of Mache</h4><p>See the GitHub README for a full explanation</p><p>After you’ve imported your data with Mache, you can parse your data with the full power of BigQuery. For instance, want to know which URLs are costing you the most to serve?</p><p>After adding Mache, just go to the <a href="http://www.blogger.com/bigquery.cloud.google.com">BigQuery browser</a> and run:</p><pre>SELECT SUM(cost) as total, path FROM [{table name}] GROUP BY path ORDER BY total DESC;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*592yzXOYB-pCROEV.jpg" /></figure><p>Or are you using App Engine’s traffic splitting feature and want to know whether the new version is serving more errors? Just run:</p><pre>SELECT SUM(IF(httpStatus &gt;= 400, 1.0, 0.0))/COUNT(*) as errorRate, versionId FROM [{table name}] GROUP BY versionId ORDER BY versionId;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*Nb5QgC5cdI9LSnnJ.jpg" /></figure><p>If you’re interested, check it out, hack on it, and let us know of any improvements you’d like to share. We think you’ll love the insight it gives you. We do.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dee7db9547" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streak-developer-blog/export-your-google-app-engine-logs-to-bigquery-introducing-mache-5dee7db9547">Export Your Google App Engine Logs to BigQuery: Introducing Mache</a> was originally published in <a href="https://medium.com/streak-developer-blog">Streak Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Butter Performance]]></title>
            <link>https://medium.com/streak-developer-blog/butter-performance-cdef530be6ee?source=rss----9a39be197112---4</link>
            <guid isPermaLink="false">https://medium.com/p/cdef530be6ee</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[streaks]]></category>
            <dc:creator><![CDATA[Aleem Mawani]]></dc:creator>
            <pubDate>Tue, 12 Dec 2017 19:52:29 GMT</pubDate>
            <atom:updated>2017-12-12T19:52:28.895Z</atom:updated>
            <content:encoded><![CDATA[<p>Performance is a top priority at Streak and is something we’re constantly working on improving.</p><p>This post goes into the different techniques we used to optimize a data heavy view in our app. Specifically, we wanted to make a 5000 row/10 column table HTML/js table feel as “buttery smooth” as a 20 row/10 column table.</p><p>At Streak, our users use the following “pipeline spreadsheet” quite heavily to see all of their data. It isn’t uncommon to have thousands of rows in the table. We also didn’t want users to have to page through rows — we think a smooth and fast scrolling experience is the ideal UX. We also need to support common table operations such as sorting, filtering, grouping, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*MCiKzuzg0W0FUFu2.png" /></figure><h4><strong>Detailed problem</strong>:</h4><ul><li>Rendering the large table should happen in under three seconds</li><li>60 frames per second should be maintained while scrolling, panning and editing cell contents</li></ul><h4><strong>Approach:</strong></h4><p>At the 2012 Google IO Nat Duca and Tom Wiltzius had a great session on jank and the process to discover and eliminate it. I highly recommend <a href="https://developers.google.com/events/io/sessions/gooio2012/209/">watching the session</a> as it provides context for the 60 fps goal and some ways on achieving that goal. What follows are the various wins we uncovered while breaking down the performance bottlenecks.</p><h3>Win #1 — Use smart multisort</h3><p>We wanted our table to allow for sorting on multiple columns. Consider a list of this can be done in one of two ways:</p><p><em>List — a collection of javascript objects with properties</em><br><em>Properties — an array of properties you want to sort by</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/0*enh7eDaew0debfq1.png" /><figcaption>Show multisort</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/0*VOGH_l7jyfxqCwmc.png" /><figcaption>Fast multisort</figcaption></figure><p>The difference between the two is the placement of the for-loop. In the slow way the for-loop happens outside the sort function which means that you’re sorting the entire list over each property. However, with multisort you only have to sort once, and in each comparison you compare all the properties. This results in a dramatic speed improvement.</p><h3>Win #2 — Sub-optimal algorithms can be much faster than optimal ones</h3><p><a href="http://en.wikipedia.org/wiki/Levenshtein_distance">Levinshtein distance</a> is the smallest number of edits required to transform one list into another using a defined set of operations. We use the edit distance to only update specific parts of the spreadsheet based on updates to the underlying data.</p><p>I coded up a modified version of the dynamic programming algorithm found on the Wikipedia article you can find here [<a href="https://gist.github.com/3078282">modified Levinshtein</a>]. What you’ll notice about this code is that it’s really bad. It’s inefficient and takes up an unnecessary amount of space even though its optimal (finds the minimum number of edits). There are simple improvements that can be made to this basic algorithm to reduce the memory footprint. Execution time can be improved using the <a href="http://ultrastudio.org/en/Four_Russians_(algorithm)">Four Russians method</a>.</p><p>However, the dynamic programming method gets us the optimal edit distance. Often in the practical world, sub-optimal is enough, and a lot faster. Furthermore, our data undergoes the same kind of changes so we can bias our edit distance algorithm to handle those changes better. <a href="https://gist.github.com/3078704">Fast Levinshtein</a> is an algorithm that runs in O(n) and produces a pretty good set of edit operations for our needs.</p><h3>Win #3 — Document fragments are fast, innerHTML is faster</h3><p>When adding a large number of nodes to the DOM <a href="https://developers.google.com/speed/articles/javascript-dom">standard practice</a> is to create a document fragment, add all the nodes to the fragment, then add them all at once to the DOM. Unfortunately, this is still too slow. The faster method is a little old school — create all the nodes using one large string, and then set the innerHTML of a container node.</p><p>Javascript (especially on Chrome) is actually really fast so constructing the string, even with a large amount of data, takes a minuscule amount of time. Setting the innerHTML of an element, even when that string is large is still substantially faster than creating thousands of nodes and adding them to a fragment individually.</p><h3>Win #4 — Event binding is slow</h3><p>If you’re not familiar with jQuery’s <a href="http://api.jquery.com/on/">on/off event API</a> take the time necessary to really GROK it as the savings are huge. Previously we were attaching event bindings to each cell, and attaching an event takes a non-zero amount of time, so multiplying that by tens of thousands of cells adds up to a lot. With the on/off API and event delegation you attach one set of events to the parent node just once. With event delegation you no longer care about the number of cells and so binding the event takes a constant one millisecond.</p><h3>Win #5 — Alternatives to overflow:hidden</h3><p>A <a href="https://bugs.webkit.org/show_bug.cgi?id=75001">known bug in Chrome</a> is that rendering elements with overflow:hidden takes a performance hit. Again, this isn’t that big of a deal for a small number of nodes, but multiplying by tens of thousands of cells results in a noticeable performance hit.</p><p>Again, refer to the Google IO talk on how to find these poor performers.</p><p>After a lot of investigation we discovered a DOM structure that would give the same visual look as a table with overflow:hidden cells, but without the associated performance penalty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/0*RYHxpbMhulxF-brQ.png" /><figcaption>Traditional table structure</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/0*fhl_-p4aNY2ok6Fr.png" /><figcaption>New table structure</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/0*4gHW3-8H7ifmwWFP.png" /><figcaption>Style for new table structure</figcaption></figure><p>The reason this works is because of the <a href="https://developer.mozilla.org/en/CSS/Understanding_z-index/Stacking_without_z-index">browser’s default stacking order</a>.</p><p>Downsides to this technique:</p><ul><li>Each cell has to have a defined width</li><li>Background color has to be defined, can’t be transparent</li><li>Cells with long contents can “peak out”of the table if you’re not careful (can have a container div around all the cells that is overflow:hidden)</li><li>Inspecting element in dev tools is really slow because of all the sibling nodes</li></ul><h3>Win #6 — Reduce number of nodes</h3><p>Previously, each cell of the spreadsheet was responsible for rendering its own read and edit contents. What this meant is that each cell would have its own set of edit controls, and while those controls wouldn’t be added to the DOM until they were necessary, there was still some containers present in memory, and the edit controls were still found in the DOM.</p><p>Similar to having one parent event binding, we moved to having one set of edit inputs that would move around depending on the cell being edited. If you look at the differences in HTML structure…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/0*_7rkwpVI1EODxb-u.png" /><figcaption>Cell with scaffolding</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/0*sUUaaJodolTaCOhi.png" /><figcaption>Cell without scaffolding</figcaption></figure><p>you’ll see that it’s much simpler and we’ve gone from three nodes to one.</p><p>That’s huge.</p><h3>Win #7 — Reduce number of visible nodes</h3><p>The spreadsheet with thousands of rows will be thousands of pixels high. Even with the latest fancy retina display in full resolution you’ll only be able to see a subset of rows. Unfortunately, the browser doesn’t know which rows are in the visible viewport and has to push every cell through at least part of the rendering pipeline. Our code <em>does</em> have a better idea of what rows are visible so we can help out the browser by only telling it to render the subset of rows that are visible. The rest of the rows can be hidden. We do this by toggling the display visibility of the rows by setting <strong>display</strong> to <strong>none</strong>.</p><p>Display is set to none instead of visibility:hidden as Chrome is able to handle display:none a lot faster. This makes sense because with visibility:hidden Chrome still has to render the cell to figure out the height and width, whereas a node that is display:none can just be removed from the render path.</p><p>This does present us with a new problem though in that the scroll bars won’t work properly. You can see how Google Spreadsheets handles this issue as they actually render the scrollbars themselves — notice how you can’t scroll a Google Spreadsheet by half of a row. We went with a different approach involving spacers which preserves the browser’s default scrollbars and results in a smoother scrolling experience…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/0*EqVbOBMqRMxzsS-W.png" /><figcaption>How spacers maintain browser’s scrollbar</figcaption></figure><p>and the associated pseudo-code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/0*dgNoRKYw32eR4MrW.png" /><figcaption>Pseudo-code for handling visibility</figcaption></figure><p>You’ll notice that while you’re scrolling we don’t hide rows that are no longer visible. The reason for this is that even with lots of rows visible the act of scrolling isn’t actually slow, but toggling the visibility of thousands of cells (if you’re scrolling fast) can lead to a jerky scrolling experience. So we set a timer that figures out when scrolling is “done” and then reset the visibility of all the rows.</p><p>The tricky part in the above code is optimizing the function “should row be visible”. This determines how performant scrolling is. The more rows you deem needed to be visible, the more toggles of visibility you do and the slower the rendering. You need to build in smarts to load a buffer of rows when you do load a new one so that you don’t do it as often — clearly there are many tradeoffs here.</p><h3>Conclusion</h3><p>Did we achieve our goals? Almost.</p><p>Initial load time went down to under 2 seconds.</p><p>60FPS is maintained most of the time, however occasionally when you’re scrolling there will be some hiccups.</p><p>Overall we’re extremely happy with what we accomplished so far. When we first started out on this project we didn’t even know if rendering a table with that many cells would even be possible. We ended up figuring out that not only is it possible, we can make it fast too.</p><p>And we can make it faster. Improvements for the future</p><ul><li><strong>Web workers</strong> — sort/filter the spreadsheet and construct the string in a web worker while changes to the data is occurring. This would get initial load to under 1 second.</li><li><strong>More server processing</strong></li><li><strong>Hybrid smart scroll</strong> — show/hide rows and also remove and readd as necessary, this may eliminate some of the scrolling hiccups as there would be a lot less nodes to RecalculateStyle on</li><li><strong>Horizontal scrolling </strong>— do a similar show/hide of columns for horizontal scrolling, again to eliminate the number of nodes to RecalculateStyle on</li></ul><p>Thanks to the web development community for all their great work and contributions. It’s only by sharing our knowledge and discoveries that we can push the web forward. Hopefully you’ll have gained a trick or two from this post, and if you have any further suggestions please let us know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdef530be6ee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streak-developer-blog/butter-performance-cdef530be6ee">Butter Performance</a> was originally published in <a href="https://medium.com/streak-developer-blog">Streak Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streak Developer Tools Chrome Extension]]></title>
            <link>https://medium.com/streak-developer-blog/streak-developer-tools-chrome-extension-76ef10cfff81?source=rss----9a39be197112---4</link>
            <guid isPermaLink="false">https://medium.com/p/76ef10cfff81</guid>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[streaks]]></category>
            <dc:creator><![CDATA[Aleem Mawani]]></dc:creator>
            <pubDate>Tue, 12 Dec 2017 19:47:45 GMT</pubDate>
            <atom:updated>2017-12-12T19:47:43.320Z</atom:updated>
            <content:encoded><![CDATA[<p>Streak is built on top of powerful platforms — Gmail and AppEngine, and wherever possible we like to build on top of those platforms. We recently started using <a href="https://developers.google.com/bigquery/">Google BigQuery</a> internally to perform logging analysis (see our logging framework <a href="http://blog.streak.com/2012/07/export-your-google-app-engine-logs-to.html">Mache</a>) and wanted to build a few tools on top of BigQuery’s great web interface.</p><p>The <a href="https://chrome.google.com/webstore/detail/lfmljmpmipdibdhbmmaadmhpaldcihgd">Streak Developer Tools (SDT)</a> is a chrome extension that currently adds functionality to BigQuery (see features below) and in the future will add other tools used internally at Streak.</p><p>Here’s what the SDT can do today with <strong>BigQuery</strong>:</p><h4>Save Named Queries</h4><p>We felt the need to be able save queries and run them again later. While the query history in BigQuery is nice, it’s sometimes hard to parse all the queries to find the one you want. We added a section in the left sidebar for saved queries.</p><p>To save a query simply type it into the query box. Also, make sure you add one line to the query which is a comment (starts with ‘ — ‘). Whatever is in that comment will be the name of the saved query. Next, hit the save query button. It’s as simple as that. This stores the query in your local storage so it is not shared with other users of the project and will not persist if you clear your local storage. We may store this online in the future.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*hUly_RSOzPWgGAKu.png" /></figure><h4>Query Across Datasets</h4><p>At Streak, we have several tables in a dataset representing log information. Often we want to query across the entire dataset. While we could manually type all of the tables into the query, we added an option to the dataset drop down that does that for you. Simply select “Query Dataset” and the query box will be filled in for you with all the tables in the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*p17XIqQAkBzQZA48.png" /></figure><h4>Show Cost of Each Query</h4><p>We also added the ability to see how much each query that you ran costs. Once the query completes, we added the cost (in US cents) next to the summary status of the query. The cost is calculated based on $0.035/GB processed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*8_0jJ3rD3gV0mq1Z.png" /></figure><h4>Expand Multi-line Results</h4><p>Since we store a lot of log data inside of BigQuery, including stack traces, many of our fields are multi-line strings which BigQuery doesn’t display very well. The SDT allows you to click on any result row and expand it to show multi-line strings. Simply click on the row number in the results table to toggle multi-line on and off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*5AGEjlu_-77YHMzq.png" /></figure><p>In order to put multi-line strings into BigQuery, make sure that your line endings are ‘\r’ and not ‘\n’ as those aren’t supported by BigQuery.</p><h4>Automatically Convert Timestamps to Human Readable Format</h4><p>AppEngine and BigQuery store timestamps as <a href="http://en.wikipedia.org/wiki/Unix_epoch">epoch time</a> which is great for computers and computation, but not so good for a human to read. The extension automatically finds, parses and replaces epoch timestamps with a human friendly date/time rendering.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/0*veqGetvLNRMpPNLC.png" /></figure><h4>Insert All Columns into SELECT Statements</h4><p>Sometimes you want to select every column in your query but typing each of them out manually takes time especially for tables with a large number of columns. In the schema description for a table, we’ve added a final yellow field called “Add All Columns” which you can press to insert all of the column names into your query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/0*U03BUOQhZfRQv1Qv.png" /></figure><p>So that’s a summary of the Streak Developer Tools and the features currently available. We’re constantly adding features to the dev tools so be sure to install the extension from the <a href="https://chrome.google.com/webstore/detail/lfmljmpmipdibdhbmmaadmhpaldcihgd">Chrome Web Store</a> so you get auto updates. We’re always looking for help — so feel free to contribute back to the project on <a href="https://github.com/StreakYC/StreakDeveloperTools">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76ef10cfff81" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streak-developer-blog/streak-developer-tools-chrome-extension-76ef10cfff81">Streak Developer Tools Chrome Extension</a> was originally published in <a href="https://medium.com/streak-developer-blog">Streak Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing the Streak API]]></title>
            <link>https://medium.com/streak-developer-blog/introducing-the-streak-api-4773a18225ec?source=rss----9a39be197112---4</link>
            <guid isPermaLink="false">https://medium.com/p/4773a18225ec</guid>
            <category><![CDATA[streaks]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Aleem Mawani]]></dc:creator>
            <pubDate>Tue, 12 Dec 2017 19:45:27 GMT</pubDate>
            <atom:updated>2017-12-12T19:45:26.915Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we’re happy to announce that we’re launching the Streak API. If you want to get started right away simply head over and <a href="https://www.streak.com/api">read the API docs here</a>.</p><p>The Streak API makes it easy to access the data stored in Streak programmatically, here are some typical calls you can make:</p><ul><li>Creating and editing boxes (super useful for setting up web forms that submit straight to Streak!)</li><li>Creating and editing pipelines</li><li>Setting up automated reminders</li><li>Searching through all your streak data</li><li>Getting a newsfeed for updates to your boxes and pipelines</li></ul><p>When we launched Streak this past March, we couldn’t imagine the tremendous response we’d receive. It’s been amazing, and all of your feedback — both positive <strong>and</strong> negative — is extremely appreciated. One of the most common pieces of feedback we’ve received can be paraphrased as: “You integrate amazingly with Gmail, but I have some other services — like MailChimp or Wufoo — that I’d like to integrate with.” We hear you, and with the release of the Streak API all of these integrations can now become a reality, as well as a heck of a lot more.</p><p>The Streak API is based on modern standards which makes it easy to incorporate into your own tools and systems, or mashup with a service like <a href="http://www.zapier.com/">Zapier</a>. I won’t go into the nitty gritty in this post, for that you can <a href="https://www.streak.com/api">check out the docs</a>, but needless to say practically everything you can do from the gmail interface you can do from the API.</p><p>To highlight some of the possibilities of what you can do with the API, I’ll use a couple of examples.</p><h4>Buyer’s Best Friend</h4><p>The first example comes from an amazing company that is leveraging modern technology to disrupt an old industry. <a href="http://www.bbfdirect.com/">Buyer’s Best Friend</a> is a wholesale specialty cataloger that helps high quality manufacturers get their products into the stores you love. Due to their focus on technology BBF has many proprietary systems they have developed in-house to help manage their business. With the Streak API they’re now totally integrating their core systems with Streak data giving their employees access to even more information, allowing them to make faster and smarter decisions. This is on both a micro level on their individual customer information, and at a macro level with forecasting, dashboards and alerts.</p><h4>Streak</h4><p>The second example is actually something that I wrote for my own use. As a developer I don’t actually spend all of my time in my inbox, I spend a considerable amount of time in my code editor (Sublime Text) and the command line. I wrote a little utility that gives me command line access to my Streak information, so I can run little arbitrary scripts and queries over my Streak data. Even in the early days with minimal functionality my utility has been surprisingly useful and I’m excited to try out other little scripts like piping things into and out of git.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/0*KYv11yx29_QOe3b1.png" /></figure><p>It’s just the beginning and we can’t wait to see how you use the Streak API to make your systems smarter and more useful.</p><p>Send us your stories and we’ll feature them here on the blog.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4773a18225ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streak-developer-blog/introducing-the-streak-api-4773a18225ec">Introducing the Streak API</a> was originally published in <a href="https://medium.com/streak-developer-blog">Streak Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Detect DOM Changes in CSS]]></title>
            <link>https://medium.com/streak-developer-blog/how-to-detect-dom-changes-in-css-ef842664ecd0?source=rss----9a39be197112---4</link>
            <guid isPermaLink="false">https://medium.com/p/ef842664ecd0</guid>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Aleem Mawani]]></dc:creator>
            <pubDate>Tue, 12 Dec 2017 19:41:43 GMT</pubDate>
            <atom:updated>2017-12-12T19:41:42.919Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is for the developers out there and is quite heavy on technical details. While <a href="http://blog.streak.com/2012/11/working-with-gmails-new-compose.html">integrating with Gmail’s new compose window</a> we ran into the issue of detecting when a compose window was open or closed. If you have Streak installed and are using the new Gmail compose you’ll notice that the controls get inserted pretty much instantly — this post is about how we accomplish that.</p><p>Traditionally the two classical methods for detecting DOM changes are: <br>1. Using a timer<br>2. Binding on the DOM mutation events.</p><p>Both methods suck.</p><p>Using a timer sucks because you have a fundamental tradeoff between performance and responsiveness. Responsiveness is defined as the time it takes for the Streak controls to appear when a new compose window is created. A short timer interval gives high responsiveness but that consumes a non-trivial amount of cycles (of which there are already few) and a large interval isn’t responsive.</p><p>DOM mutation events suck because there’s a huge performance penalty on them and they’re being deprecated from browsers in the near future.</p><h4>Enter CSS.</h4><p>David Walsh wrote <a href="http://davidwalsh.name/detect-node-insertion">a blog post on detecting DOM node insertions using CSS</a> based upon <a href="http://www.backalleycoder.com/2012/04/25/i-want-a-damnodeinserted/">a technique by Daniel Buchner</a>. The high level overview is that you define an animation (with a very low performance cost) and give it a unique name. You then apply that animation to the DOM node selector you’re interested in. Attach a document level binding on animation complete and the event callback not only tells you which animation finished (so you can switch case on the ones you’re interested in) but also gives you the node you’re looking for!</p><p>While the blog post specifies the technique for detecting insertions, we realized that this technique can be generalized to send an event whenever the DOM hits a particular state that you’re interested in. By carefully creating your CSS selectors and making judicial use of nth-child and nth-last-child you can know whenever a specific kind of node is inserted <em>or</em>removed. For removal there’s an extra bit of javascript that’s required to determine which node is removed, but it’s not that big of a deal.</p><p>What we implemented specifically for the Gmail compose windows were two selectors and two animations which you can see here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/0*cYsl2eQy7hj3zhjm.png" /></figure><p>As you can see there are two animations, and two style definitions, one for an odd number of compose windows, and one for an even number of compose windows. Notice how the clip goes from 0-&gt;1 for odds and 1-&gt;0 for evens. This way every time the number of compose windows changes a new event fires. We can do things this way since in Gmail you create or destroy a compose window one at a time.</p><p>If you have other cool and useful techniques then please share!</p><p>Or, if you’re looking to work and hack on other cool technical challenges like this then check out <a href="http://www.streak.com/jobs">our jobs page</a> as we’re always looking for talented developers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef842664ecd0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/streak-developer-blog/how-to-detect-dom-changes-in-css-ef842664ecd0">How to Detect DOM Changes in CSS</a> was originally published in <a href="https://medium.com/streak-developer-blog">Streak Engineering Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>