<?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 w. ian douglas on Medium]]></title>
        <description><![CDATA[Stories by w. ian douglas on Medium]]></description>
        <link>https://medium.com/@iandouglas736?source=rss-bd019600d679------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kVGamo1D9S7ktBiY7guXZQ.jpeg</url>
            <title>Stories by w. ian douglas on Medium</title>
            <link>https://medium.com/@iandouglas736?source=rss-bd019600d679------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 16:36:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iandouglas736/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[Balance or Burnout]]></title>
            <link>https://iandouglas736.medium.com/balance-or-burnout-7960af1a1251?source=rss-bd019600d679------2</link>
            <guid isPermaLink="false">https://medium.com/p/7960af1a1251</guid>
            <category><![CDATA[teaching]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[hiring]]></category>
            <category><![CDATA[career-change]]></category>
            <dc:creator><![CDATA[w. ian douglas]]></dc:creator>
            <pubDate>Fri, 11 Jun 2021 19:31:22 GMT</pubDate>
            <atom:updated>2021-06-11T19:31:22.694Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hudRoioxf91K979W" /><figcaption>Balance or Burnout, photo by Nataliya Vaitkevich, pexels.com</figcaption></figure><p>It’s hard to sit still.</p><p>Something has always stirred in me…</p><p>“Keep learning. Keep stretching. Do more. Get better. Apply it. Show others.”</p><p>I don’t know when this started as a kid. I had a knack for learning things, practicing, and then excitedly showing others. “You can do this TOO!” I’d sit and make my friends play a jingle on a piano. Type some BASIC code on my Commodore 64. Make something practical/functional out of Lego building bricks. Never with the mindset of “Ian taught me”, but to encourage “I can do this new thing.”</p><p>High schoool: same.</p><p>College: same.</p><p>In my tech career: plenty more of the same.</p><p>This is why I’ve been such an advocate of the Agile methodology and Test-Driven Development. Constant feedback, constant tweaking, constant growth.</p><figure><img alt="growth; photo credit to Akil Mazumder, pexels.com" src="https://cdn-images-1.medium.com/max/500/0*PGkXZTMW7U9PME3K" /></figure><p>Jeff Casimir sent me a DM on Slack in the summer of 2017. What would it take to join the staff at Turing? It was an easy decision. <a href="https://iandouglas736.medium.com/a-major-career-pivot-c36256667ebe">I wrote about it here</a>.</p><p>Turing has made me a better instructor. We’re consantly trying new ways to present information better. Or encourage learning within our students and more. We’ve studied inclusion, equity, compassion and empathy. These have resonated with me and have helped me grow as a human.</p><p>In March 2020, Turing went remote with most of the world. <em>I wasn’t a fan.</em> I missed being in the classroom. Student engagement is harder in a remote setting, especially for introverts. Turing made it work. We came up with new ideas, new goals, new structure.</p><p>I overspent on hardware. New monitors, desk, lights, cameras, bandwidth. Whatever made me feel I had everything to be present for my students.</p><p>The cameras and lights only gave spotlight and stage to my workaholic tendencies. It happened earlier in my career when I did freelance work in California. Apparently, I have no off switch without a commute to an office. Something about that drive helps me unplug on the way home.</p><p>Turing staff were told in December 2020 that we would be remote on a permanent basis. We would announce it in February 2021. I spent most of the Christmas season in a state of mourning. I was never going to get back to a classroom, and I was losing my battle with overworking.</p><p>Turing’s enrollment is stronger than ever. People didn’t have to move to Colorado to attend our classes. We had people <strong>around the world</strong> applying to attend Turing. I currently have students from all over the United States and it’s freakin’ <strong>FANTASTIC</strong>.</p><p>But I was getting antsy.</p><p>I wanted more.</p><p>Can’t sit still.</p><p>Do more, work more … how can I teach more? MORE!</p><p>Even my side hustle on <a href="https://interviewing.io/">interviewing.io</a> was starting to feel routine. I thought I needed a new challenge.</p><h3>Trying to do More with Less</h3><p>I approached upper management at Turing and shared my ideas for “electives”. Maybe I could write some new curriculum around deeper engineering topics. Students could explore topics and workshops on subjects that could direct their career. Perhaps other instructors, as well — I care just as much about THEIR growth, too. Turns out management had been thinking the same thing. I was the only “senior” instructor on staff, and they were already discussing utilizing my experience at the school in new ways.</p><p>But my work hours were leading me to a place of burnout, and emotional exhaustion was setting in. My anxiety heightened in the spring of 2021 with a student and I found myself emotionally overreacting. I was near a breaking point.</p><p>But … MORE!!!</p><p>Other things happened in April and May of 2021, that I won’t go into here. I’ve often dealt with “imposter syndrome” in my career. But this took on an entirely different feeling. Not the typical “I’m not qualified to do this job” kind of imposter syndrome. I was made to feel that I was being viewed AS an imposter. I’d been in the community for 7 years, but I wasn’t “of” Turing. I had never been a student at Turing like most of the other staff. I felt very often that I never “belonged” there. And that feeling got magnified.</p><p>It took my already-heightened anxiety to new levels, and I was sleeping less than 3 hours per night. Chugging coffee and Diet Dr Pepper to get through the day. Crashing on the couch after dinner. Then being wide awake again into the wee hours. It was draining the remains of an already-empty tank.</p><p>It made me a little loopy, not gonna lie.</p><p>It helped me see and set appropriate boundaries for the first time in AGES.</p><p>It also drove me to seeking therapy.</p><p>This whole experience drove me to seeking external motivational help from any source I could find. The comedian Kevin Hart, despite his foul language, <a href="https://www.audible.com/pd/The-Decision-Audiobook/B084GYSS73">narrates an audiobook</a> that was surprisingly eye-opening. I’m on my second listen already.</p><p>As I would learn, external motivation is like a sugar rush — it only gets you started. You need to find INTERNAL motivation, purpose and meaning, to keep you going.</p><p>The circumstances made me pause for the first time in a long time. I started to have some quality “me” time, while I reflected on things. I journaled. I shared my feelings. I found confirmation that something needed a change.</p><p>A new job, maybe? Aw, f__k, I’m gonna have to go on <strong>interviews</strong>?!?!</p><h3>Turns out other things were lining up anyway.</h3><figure><img alt="plantetary alignment in March 2021; photo credit to SmithsonianMag.com" src="https://cdn-images-1.medium.com/max/800/0*6ZmOZ-Pe78ki-Sco.jpg" /></figure><p>I worked at <a href="https://getstream.io/">Stream</a> right before Turing. With a fresh round of funding an new offerings, Stream is growing at a wild pace. The CEO never wanted the company to be bigger than 50 employees in 2017. In 2021 they’re on track to hit 200 employees, including 60 engineers in the second half of 2021. They were also planning to have someone on staff to help teach/onboard those new engineering hires. Doing so would help them focus hiring on “good, smart people” who Stream could train in their desired tech stack. Ideally, this would open their hiring process to be more equitable.</p><p>I took an afternoon off, and a 90-minute conversation turned into a job offer.</p><p>For the fourth job in a row, I had no real formal interview process. No whiteboarding, no leetcode.</p><p>Reputation and merit alone granted me a role of <strong>Director of Engineering Learning</strong>.</p><p>Onboarding curriculum, video tutorials, blog posts, occasional live (!!!) teaching — to the engineering team in Amsterdam, hopefully! All on those deeper engineering principles I’ve been yearning for. Go, RocksDB, PostgreSQL, scalability, data security, AWS, Git workflows, deployment strategies. All with a promise that I can open-source anything not containing proprietary secrets.</p><p>“This isn’t the only way, but this is Stream’s way” will be the motto I will carry into this new role.</p><h3>What about Turing?</h3><p>I still believe VERY much in the mission at Turing. It’s a great coding school to learn the basics of web development in Ruby or JavaScript. The curriculum is great. The career support is second-to-none.</p><p>I have learned SO much from many of the instructors there. Some of them were my own students or mentees. I wouldn’t have grown in areas of empathy and humanity as quickly without amazing examples. Dione, Leta, Meg, Tim, Pam, Erin, Amy, Travis, Josh, and more.</p><p>But it’s also time for a break.</p><p>I’ve been a part of the Turing community for almost 7 years (~3 as a mentor, ~4 as an instructor).</p><p>I’ve given of myself.</p><p>My time, my sweat, my energy, my tears.</p><p>Tank’s empty.</p><h3>Oh come on, there’s always a side gig…</h3><p>I have no plans for any side gigs for a little while. I’m taking some much needed time off before I go back to Stream. And I have a lot to ramp up on myself and a ton of work ahead of me.</p><p>Mostly I want to focus on self-care, and finding balance. That means scaling back on one-on-one coaching and finding ways of reaching groups of people instead. I’m going to try some <a href="https://twitch.tv/iandouglas736">live streaming around interview prep</a> later this summer.</p><p>You can track my doings on <a href="https://twitter.com/iandouglas736">Twitter</a>, <a href="https://linkedin.com/in/iandouglas736">LinkedIn</a>, and my <a href="https://techinterview.guide/">tech interview preparation guide</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7960af1a1251" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Publish and auto-deploy a Hugo Static Site on Firebase using GitHub and Travis-CI]]></title>
            <link>https://iandouglas736.medium.com/publish-and-auto-deploy-a-hugo-static-site-on-firebase-using-github-and-travis-ci-57d0e19de1c5?source=rss-bd019600d679------2</link>
            <guid isPermaLink="false">https://medium.com/p/57d0e19de1c5</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[hugo]]></category>
            <category><![CDATA[workflow-automation]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[static-site]]></category>
            <dc:creator><![CDATA[w. ian douglas]]></dc:creator>
            <pubDate>Tue, 01 Dec 2020 00:19:14 GMT</pubDate>
            <atom:updated>2020-12-01T00:19:14.279Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="“That’s quite a mouthful”" src="https://cdn-images-1.medium.com/max/572/0*0VZNywx9VymHLe_F" /><figcaption>whew, that’s a REALLY long blog title …</figcaption></figure><p>I have several static web sites that I maintain and deploy manually, including <a href="https://iandouglas.com/">iandouglas.com</a> and <a href="https://techinterview.guide/">techinterview.guide</a>. It’s not always convenient to be on my typical development machine to write something in markdown, run my static site generation, and deploy the new pages, so I wanted to build a workflow that will allow me to use my browser alone going forward.</p><h3><strong>Step 1: Build an empty Web project on Firebase</strong></h3><p>I use Firebase for hosting my static sites for several reasons:</p><ul><li>Google scale, not that anything I’ve done lately has gone viral, but:</li><li>Google’s free quotas are extremely generous: 10GB of storage, 10GB/month to your readers and $0.15/GB after that; this feels like “unlimited” for small-scale sites.</li><li>free SSL/TLS, helping with SEO, cookies, general web safety, etc..</li><li>attach custom domains to your project; authenticating ownership of the domain is super simplified if you transfer your domain to <a href="https://domains.google/">Google Domains</a> first</li></ul><p>Visit <a href="https://firebase.google.com/docs/web/setup">https://firebase.google.com/docs/web/setup</a> to get started with a web-based project.</p><h3><strong>Step 2: Start a static site using Hugo</strong></h3><p>Visit <a href="https://gohugo.io/getting-started/quick-start/">https://gohugo.io/getting-started/quick-start/</a> on how to get started with a Hugo static site. I love using Hugo because everything is in Markdown, there are <a href="https://themes.gohugo.io/">lots of great themes</a> available, and the fragments of code you write are Go-based. (Hugo is written in Go)</p><h3><strong>Step 3: Put your work in a GitHub repo</strong></h3><p>Your project doesn’t need to be in a public GitHub repo for this to work. My static site repos are usually private. Start a repo, commit your work in there.</p><h3><strong>Step 4: Get your GitHub repo visible on Travis-CI</strong></h3><p>Okay, wait. Travis-CI? Why not just use <a href="https://firebase.google.com/docs/hosting/github-integration">GitHub Actions for Firebase</a>? Yeah, you could probably go that route though I didn’t look into it too deeply to see how to install and run Hugo to actually build the site. If you run Hugo locally and check in the generated HTML, images, etc, then GitHub actions would probably be more suitable.</p><p>I’m also a bit of a nut when it comes to testing things, making sure content exists on pages correctly, and I can tell Travis-CI to do some of the other work I’d typically do on my development workstation as part of its deployment that I’ve found harder to do using GitHub actions.</p><p>Get set up on Travis-CI.com (you’ll need to authenticate through GitHub for this to work to see your repos). Once you can see your repo on Travis you’re most of the way there.</p><h3>Step 5: Build a .travis.yml file to do the deployment</h3><p>This step is busy:</p><p>a. Install the Travis-CI gem (“<strong>gem install travis</strong>”) to give yourself access to the “travis” command line interface.</p><p>b. Install the Firebase CLI tools (“<strong>npm install -g firebase-tools</strong>”) to give yourself access to the “firebase” command line interface. Make sure you use the <strong>-g switch</strong> to install globally, or it’ll build a node_modules folder in your Hugo project which you probably don’t want at the root level of your project.</p><p>From here, you’ll need to authenticate to firebase from your project directory on your development machine using “<strong>firebase login</strong>”. This will open a browser where you’ll OAuth to Firebase. It should update the terminal prompt to say something like:</p><pre>Waiting for authentication...</pre><pre>✔ Success! Logged in as ian.douglas@iandouglas.com</pre><p>Follow that with “<strong>firebase login:ci</strong>” where it’ll prompt you again in a browser to give your agreement to this step, at which point you should see something like this in your terminal:</p><pre>Waiting for authentication…</pre><pre>✔ Success! Use this token to login on a CI server:</pre><pre>2//0lkjaeflinsifnseflnaknwd9305029385laskdfj</pre><p>You’ll copy that cryptic looking line (it’ll be much longer than what I have above) and do the following steps in your terminal in the base path of your project (where your config.toml file and “content” folder and so on would exist for your Hugo project)</p><pre>touch .travis.yml<br>travis encrypt &quot;2//0lkjaeflinsifnseflnaknwd9305029385laskdfj&quot; - add</pre><p>This should prompt you to overwrite the file you just “touched” to create the file in the first place. Say “yes” at the prompt to allow it.</p><p>Now comes the whole .travis.yml file where we need to tell it which version of Hugo to download, and then I’ll talk about extra steps I do as part of my deployment:</p><pre>install:<br>  - curl -LO <a href="https://github.com/gohugoio/hugo/releases/download/v0.71.1/hugo_0.71.1_Linux-64bit.deb">https://github.com/gohugoio/hugo/releases/download/v0.71.1/hugo_0.71.1_Linux-64bit.deb</a><br>  - sudo dpkg -i hugo_0.71.1_Linux-64bit.deb</pre><pre>script:<br>  - rm -rf public/*<br>  - hugo</pre><pre>deploy:<br>  provider: firebase<br>  skip_cleanup: true<br>  on:<br>    branch: main<br>  token:<br>    secure: BZaL.... whatever the travis gem put here for you</pre><p>Let’s break this down:</p><p>The “install” block is where we’ll use the “curl” command to tell Travis-CI to download a copy of Hugo. Use a 64-bit Linux Debian package, which you can grab once you choose a version from <a href="https://github.com/gohugoio/hugo/releases">https://github.com/gohugoio/hugo/releases</a>. I scrolled to v0.71.1 which I use on my development machine, clicked on that version number, and from there got the Linux 64-bit “.deb” package download link.</p><p>Next we’ll use “sudo” to tell Travis-CI to install that debian package so we’ll have access to run the “hugo” command later.</p><p>The “script” section is where we tell the CI platform to execute some commands for us. Since I may already have some files in my repo under the “public” folder that will just get rebuilt anyway, I delete all of those files first (but not the public folder itself). Then I tell it to run the “hugo” command which rebuilds my static site.</p><p>Last is the “deploy” section where we can specify “firebase” as our deployment target. We “skip_cleanup” so that new files aren’t deleted before deploying. The “on” command specifies which branch to deploy, and the “token” portion is the secured, encrypted version of that “2//whatever” string that Firebase gave us earlier. <strong>Do NOT put the “2//whatever” string in there itself as that’s an unencrypted API key, especially if your repo is public.</strong></p><p>From there, you should be able to push that .travis.yml file up to GitHub and see if Travis-CI does a build and if that passes, deploy to Firebase.</p><h3>Net Result: Modify or add markdown pages directly on GitHub and they’re deployed a few minutes later.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*LXct341cJfSEtfmq.gif" /></figure><p>The only caveat I have is for my Tech Interview blog where I generate a CHANGELOG, I’d need to work out a way to start a pull request on GitHub, alter several files, and then push them all at once so I’m not cluttering up my commit logs.</p><p>And speaking of that:</p><h3>Extra Things I Add in My .travis.yml file</h3><p>As I mentioned above, I do extra stuff when I do my Hugo builds. I can run tests to make sure that once the site is done that links show up on the page, etc.. There are a myriad of tools you can use for this that you can set up in your .travis.yml file like Python and BeautifulSoup or any spidering tool that looks for broken links etc..</p><p>One thing I do is build a CHANGELOG file of my commit messages for users to track what I’ve changed on my Tech Interview site, so I need to install Node.js to run some JavaScript code to build a running Markdown file of my commit messages.</p><p>I also have a “clean_content.sh” script that I run that converts fancy quotes to plain quotes, eplises into literal “...” strings, and so on.</p><p>So my .travis.yml for one site might look something like this:</p><pre>install:<br>  - curl -LO <a href="https://github.com/gohugoio/hugo/releases/download/v0.71.1/hugo_0.71.1_Linux-64bit.deb">https://github.com/gohugoio/hugo/releases/download/v0.71.1/hugo_0.71.1_Linux-64bit.deb</a><br>  - sudo dpkg -i hugo_0.71.1_Linux-64bit.deb<br>  - . $HOME/.nvm/nvm.sh<br>  - nvm install stable<br>  - nvm use stable</pre><pre>before_script:<br>  - node -v<br>  - npm install npm -g</pre><pre>script:<br>  - rm -rf public/*<br>  - sh clean_content.sh<br>  - node changelog.js<br>  - hugo</pre><pre>deploy:<br>  etc etc</pre><p>NVM is installed by default on Travis, so we just tell it to activate that NVM environment, install the latest “stable” version of Node and to “use” that version. The “before_script” portion then just ensures that Node is in fact running (or the “testing” will fail and halt), and then update NPM. At this point I can run “node changelog.js” in my “script” section to build my <a href="https://techinterview.guide/changelog/">CHANGELOG page</a>.</p><p>Image credits: Pinterest, BallMemes</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57d0e19de1c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Technical Interview Preparation for the newcomer to our industry]]></title>
            <link>https://iandouglas736.medium.com/technical-interview-preparation-for-the-newcomer-to-our-industry-58ea6fb2f115?source=rss-bd019600d679------2</link>
            <guid isPermaLink="false">https://medium.com/p/58ea6fb2f115</guid>
            <category><![CDATA[coaching]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[w. ian douglas]]></dc:creator>
            <pubDate>Fri, 16 Oct 2020 15:40:41 GMT</pubDate>
            <atom:updated>2020-10-16T15:40:41.745Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s start with this:</p><p><strong>You belong.</strong></p><p>Whoever you are, whatever your background, you bring something to tech that none of us have seen before. You have a perspective we need to hear, you have stories we’ve never heard, and you’re going to approach problems in ways we may never have imagined. Welcome to the team.</p><p>Our industry is full of bias, and I’m pretty sure it’s the only white-collar job that requires you to prove you can do the job before getting a job offer. You never hear of doctors applying for jobs and being told, “Go perform brain surgery on this patient; if they live, you get the job.” But that’s exactly what our software industry feels like.</p><p>Medical degrees come with review boards and credentials. Law degrees have the “bar exam”. Even tradeskills have licensing committees that put their name behind you — that you have been trained in a particular discipline. Others who trust that committee/credential/etc can therefore trust you have a minimum amount of knowledge and skill.</p><p>Our industry, however, has no such thing. Unless you have a degree from a prestigious school, or other “credential”, but those must be inherently “trusted” by those screening your appliction, reading your resume, looking for reasons to say “no” to thousands of you applying for one job.</p><p>Ethics aside … <strong>our industry has a very broken sense of trust.</strong> Our interview process reflects that for how many hoops we have to jump through to prove we can do the work before we can get a job. The first time I think I was “trusted” was interviewing at a startup in Boulder, CO. Their Director of Engineering at the time offered me the opportunity to come by and meet their team. I asked if I should prepare for the full-scale technical interview. “No, you’ve been working at SendGrid for 4 years — if you were incompetent, they’d have fired you long ago.” And that was that, I had a new job. This was also <strong>15+ years</strong> into my career.</p><p>See, I didn’t come from a prestigious university. I went to community college in Canada. My 3-year diploma as a Computer Engineering Technologist was slightly more than an Associate’s degree in the US, but looked down upon by those requiring a Bachelor’s degree.</p><p>Over the years, I’ve been a team lead, managed small teams within engineering departments, helped sculpt and define interviewing processes, and been in charge of engineering hiring, consulting work and technical coaching. I’ve argued against “requiring” bachelor’s degrees, I’ve advocated for non-degree holders to get interviews. We still have a long way to go.</p><p>In the meantime, I’ve written a TON of material that I consider helpful to the new developer in the tech industry.</p><p>It started as 30+ pages of a Google doc that was shared around, person to person, having repetative calls with folks, telling them the same things about resume formatting, negotiation ideas, etc.. So I decided the best way to “scale” this information was to publish it online.</p><p>So I moved everything to techinterview.guide, including a daily email series:</p><p><a href="https://techinterview.guide/">Book :: Tech Interview Prep with Ian</a></p><p>Aside from the work-in-progress text about resumes, cover letters, interview prep work, I also <a href="https://techinterview.guide/daily-email-series/">wrote an email series — a 42-message series</a> that takes about 5 minutes per day to read and digest. I review common interview questions, but from an interviewer’s perspective. Why am I asking this kind of question? What do I hope to hear in your answer? What don’t I want to hear in your answer?</p><p>As for the book content, I’ve slacked on getting some updated material written and have a few chapters to finish, but wanted to get it out there for folks who are looking for assistance.</p><p>I also recently wrote an article for interviewing.io about <a href="http://blog.interviewing.io/ive-conducted-over-600-technical-interviews-on-interviewing-io-here-are-5-common-problem-areas-ive-seen/">common problem areas I see as a professional interview coach</a>.</p><p>Find me on <a href="https://linkedin.com/in/iandouglas736">LinkedIn</a> if you want to connect and ask for help.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58ea6fb2f115" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[(Literally) Creating Engagement in the Classroom]]></title>
            <link>https://iandouglas736.medium.com/literally-creating-engagement-in-the-classroom-3f952dd7294c?source=rss-bd019600d679------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f952dd7294c</guid>
            <category><![CDATA[classroom]]></category>
            <category><![CDATA[3d-printing]]></category>
            <category><![CDATA[student-engagement]]></category>
            <category><![CDATA[turing-school]]></category>
            <dc:creator><![CDATA[w. ian douglas]]></dc:creator>
            <pubDate>Wed, 20 Mar 2019 04:55:01 GMT</pubDate>
            <atom:updated>2019-03-20T05:05:33.625Z</atom:updated>
            <content:encoded><![CDATA[<p>I teach at the <a href="https://turing.io/">Turing School of Software &amp; Design</a>.</p><p>The Executive Director, Jeff Casimir, invested in a lot of tech-adjacent cool stuff that hangs out in the “Vault” room at Turing, including bins of Arduino boards and kits of parts like LEDs, resistors, motors, etc.. And a big-@$$ 3D printer.</p><p>When Jeff offered me the job at Turing, he probably could have offered me a lower starting salary just by uttering the words “we have a 3D printer”, but don’t tell him I said that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UPNuJH05dkiR-O4d" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/0*A9pTYyiO8biVyudC" /></figure><p>From early November through the winter break ending 2017, if I wasn’t in the classroom, or helping students prepare for technical interviews, I was probably in the Vault, messing with the 3D printer. My first prints included “Om Nom” from the old “Cut the Rope” game, and a Baby Groot.</p><p>The prints weren’t great. Lots of “banding”, but this printer hadn’t seen a lot of use, or maintenance love, but for what we had, it was in really good shape. Of course, there was a fair share of nerdery going on as well for things like Star Trek icons, but I also got into designing and printing some “functional” prints that were more than trinkets to sit on a shelf. I printed a new shell for a failed power supply for the 3D printer that we replaced but had “mains power” exposed, and, well, I didn’t really want to electrocute any students…</p><p>But that got me to thinking about other ways we could embark on a more dynamic way of generating functional prints within the school.</p><h3>Engagement Tools</h3><p>In the classroom there are lots of ways to keep students engaged, and one technique we employ a lot are “draw a name” techniques. Essentially, we teach some theory, give students a few moments to think of an answer to a question, and draw a wooden tongue depressor with their name written in Sharpie marker. This ensures that (a) the students are paying attention, and (b) we see a random variety of students being called upon, instead of just opening a Q&amp;A session where maybe the same few students ask the majority of the questions.</p><p>“Surely we can do better than wooden sticks and Sharpie marker to engage students,” I said to nobody in particular one day in January 2018, and with a little knowledge in my head, the 1801 Cohort at Turing became the first recipients of 3D printed “popsicle sticks”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/0*KeKMvYnP4SuvNNg9" /></figure><p>By this time I was also thoroughly hooked on 3D printing, having made several Christmas gifts, a giant Mario “?” Cube suggestion box for Turing, and numerous other interesting things, and I ordered a 3D printer for my home which gets nearly daily use.</p><p>Another instructor at Turing took these initial blue popsicle sticks, painstakingly painted their names in gold paint, and then we had a hit on our hands. But there had to be a way to make popsicle sticks in a way that didn’t require hours and hours of painting detailed names.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xHGQ9R2SzNGoiEa0" /></figure><p>Once my 3D printer arrived at home, a Prusa i3 MK3, I set out to find ways to utilize “multi-color” printing at specific layer heights, and my first results replaced the 1801 Cohort’s sticks from blue/gold to green/white.</p><p>Each popsicle stick took, on average, 20–25 minutes each.</p><p>This would lead to finding new color combinations for future cohorts along the way:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*05s_0sGWD3b6FJBG" /></figure><p>It would even lead to one staff member asking for their own popsicle stick big enough to beat people with for misspelling/mispronouncing her name. I won’t name names, though…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/0*N10YxgjtAbZBH_Vp" /></figure><h3>The Process</h3><p>A mentor once gave me the phrase “<a href="https://qr.ae/TW8Gjx">humans are not scalable</a>”, and the process of designing each of these popsicle sticks, laying them all out in my 3D printing software wasn’t a HUGE amount of time invested, but it was still several hours of work to get all of the student names each inning, generate the sticks, place them in the printing software, generate the code the printer uses to actually generate them, plus the many, many hours to actually print them.</p><p>The problem was, with large cohorts, I could only fit so many sticks on the print bed at the same time, resulting in many trays where I had to manually arrange the sticks to print. Sometimes they were too close and melted together. Sometimes they were too far away to fit as many on the printer as I could do optimally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3FgegRSDaEchu2Ia" /></figure><h3>Automation (mostly) For the Win</h3><p>Using some open-source software, called <a href="http://www.openscad.org/">OpenSCAD</a>, I was able to redesign the popsicle sticks in a slightly smaller format using a <a href="https://www.thingiverse.com/thing:1204005">model created by Aaron Ciuffo</a> and customize the scripting in his model to generate popsicle sticks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*8ODTqQYkUZWhUDgezTOHXw.png" /></figure><p>30% less plastic (which is biodegradable, by the way!) than my previous process, but still 100% of the engagement in class!</p><p>I exported Aaron’s script to something I could import into Ruby and do a simple search-and-replace, allowing me to import a list of student names in CSV format, run a shell script to run my Ruby script, and output individual OpenSCAD scripts for each student. OpenSCAD, then, has command-line options for batch-producing the models, and thanks to modern hardware I can produce dozens of sticks in less than two minutes. This saved an enormous amount of time to generate the individual popsicle sticks, down to a few mere minutes to generate sticks for a whole class. But it would still take me even more minutes to manually arrange them to print crammed together on the print bed.</p><p>But, now I can edit a CSV file, enter one or more student names, generate a stick, drop it in my printer software, and export a few sticks at a time in less than 5 minutes. Each stick takes about 12 minutes to produce on the printer.</p><h3>Can’t Stop, Won’t Stop</h3><p>I wasn’t content. There had to be a way to make it even easier to place all of the popsicle sticks in one shot, and then it hit me.</p><p>What if OpenSCAD could take a list of student names, instead of one at a time, and lay out all of the sticks and export that as one big model instead of one model per student?</p><p>Turns out I could, and I could also tell the software to output the models *really* close together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tcqlFSJJZo1i-dnw4n14mg.png" /></figure><p>The result: instead of manually placing 16 or so sticks on the print bed with my old design, increased to 24 or so with my new design, now I can print 32 popsicle sticks on the print bed in one go. Generating this large 3D model takes about the same amount of time as generating 32 of them individually, but I’ve saved myself quite a lot of time having to lay them out in the printer software:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*7yj8w6XPssFOpxp_chyQxg.png" /><figcaption>turns out staff members want engagement too!</figcaption></figure><p>All I need to do then is insert the instruction to change the filament color at a given height, and we can send the file to the printer.</p><p>And the result was so great I even printed a 3D cup to hold them all:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3_NA9SKoicnttFGZnys4Iw.jpeg" /><figcaption>Stop counting, there aren’t 32 in the cup… I needed to reprint two of them</figcaption></figure><p>6 hours, 32 staff members, about 11 minutes per stick. Half the time it would have taken previously.</p><h3>The Dinosaur Lives Again</h3><p>So what about that old, big, clunky 3D printer at Turing? Well, we got it some upgrades, and students are having fun printing their knick-knacks, but some of them are also printing functional prints as well. I run an occasional class to teach students how the 3D printer works, and get them involved in coming up with designs.</p><p>The new upgrades will also support multi-color layered prints as well but it takes more manual intervention than my MK3 at home.</p><p>In the meantime, rock on!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FqbrIOlkP8RQ%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqbrIOlkP8RQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FqbrIOlkP8RQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3dc5c458b4928bd98c5c480bcfd05bc3/href">https://medium.com/media/3dc5c458b4928bd98c5c480bcfd05bc3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f952dd7294c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Iterative Improvement]]></title>
            <link>https://iandouglas736.medium.com/iterative-improvement-96fe104d30bf?source=rss-bd019600d679------2</link>
            <guid isPermaLink="false">https://medium.com/p/96fe104d30bf</guid>
            <dc:creator><![CDATA[w. ian douglas]]></dc:creator>
            <pubDate>Sat, 02 Mar 2019 13:04:17 GMT</pubDate>
            <atom:updated>2019-03-03T02:37:45.722Z</atom:updated>
            <content:encoded><![CDATA[<p>I was challenged this week in a “hot seat&quot; Q&amp;A session with my students about what my next big goal is in life. They also asked fun questions like how I convinced my wife to date me, and had I ever done anything illegal like hack into a computer. But this “next big goal” question startled me. I answered just about every other question without hesitation, but this one…</p><p>My entire life has been filled and fueled by curiosity. As a kid, I would tear things apart to see how they worked inside. When my dad bright home a <a href="https://en.wikipedia.org/wiki/Commodore_64">Commodore 64</a> in the early 80’s, suddenly I could take digital things apart too and not have to worry as much about reconstruction of the now-destroyed plaything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/0*-h9zEjsIIKAZPDnd.jpg" /><figcaption>image credit: <a href="http://oldcomputers.net/c64.html">oldcomputers.net</a></figcaption></figure><p>As a teenager I was into art and music, and math and science were necessary discomforts to my high school education. Looking back I guess I never had science or math teachers who tapped into my curiosity. I love the subjects now. I barely passed high school chemistry (51% was, technically, a pass), and now I love watching chemistry related things on YouTube.</p><p>Starting in electrical engineering and switching my major later to computer engineering helped solidify a career choice I’d made as an 8yr old breaking down video games written in BASIC. I’d found an industry that would never satiate my curiosity and drive to learn.</p><p>In the workforce, I’ve purposefully put myself in a ton of different industries learning how things work in the works around me, and how technology plays a part.</p><p>I’ve worked on operating systems software at <a href="https://blackberry.qnx.com/en">QNX </a>support and sales engineering roles. I’ve been in a systems engineering team at what is now March Networks, working on fiber optics systems, and satellite-based audio transmission systems. I worked in cryptography firmware at Chrysalis-ITS on hardware-based network security.</p><p>Moving to California, I worked at <a href="https://icreditvision.com/">iCreditVision</a> on credit reporting software and learning how personal credit worked to one’s advantage. I spent a year building out an online education platform at OUOA to build remote classrooms and on the fly quiz/polling systems. I got into e-commerce systems at PriceGrabber to learn how digital commerce was changing the world. I got into political systems working at the <a href="https://www.lacoe.edu/">Los Angeles County Office of Education</a> building threat response portals for schools. I spent some time working on entertainment software for Fox Networks. Online advertising wasn’t something I was super keen on at the time but the complex map-reduce system I built at <a href="https://rubiconproject.com/">The Rubicon Project</a> managed analytics data for several trillion ad impressions in near real-time. I pursued gaming for a while and built out community platforms and micro-transaction systems at <a href="https://armorgames.com/">Armor Games</a>.</p><p>Then onto more complex systems and architecture work at <a href="https://sendgrid.com/">SendGrid</a> learning how email and email marketing worked. Then a brief stint as Director of Engineering at Simple Energy, followed by failed Growth Hacker position at <a href="https://getstream.io/">Stream</a> which pivoted into highly successful Developer Relations work.</p><p>And then I joined the instructional staff at <a href="https://turing.io/">The Turing School of Software and Design</a>. Here, I get to share the knowledge and wisdom gained over 23 years as a developer. If you factor in when I got the Commodore 64 and taught myself BASIC programming, I’ve actually been writing code for closer to 36 years.</p><p>Every Friday at Turing my students are sent a survey asking them what they enjoyed about their week. What did we do well to make them feel included in the classroom, what did we do well in our lessons to keep them engaged, and how can we improve.</p><p>The latter question, to me, is the most important. <strong>I’m very self-critical</strong> and sometimes focus too much on the input from students on suggestions where I can improve. It’s good because I can set goals around those improvements, but also bad because I can become a pendulum swinging from over-simplifying concepts to not simplifying the ideas enough. I have definite blind spots when it comes to the perspective of being a student in technology when it’s been such an important piece of my <strong>entire</strong> life.</p><p>But I still long for ideas on improvement, and I deeply appreciate the time my students take to fill out these surveys.</p><p>Hanging on my office wall are little notes of affirmation that other staff members have written about me. I have a mini-gong on my desk as a thank you for spending three years mentoring students at Turing before joining staff full time. I keep letters and cards from students thanking me for my time and effort helping them at Turing. I surround myself with these positive things, yet I still crave the critical feedback to help me improve.</p><p>Through this feedback, I take a very Agile approach to iterative design, applying it at a personal level. What’s one thing, maybe two things, I can change this coming week to make a lesson more engaging? How can I find better analogies to explain concepts to people in my classroom who haven’t had nearly 40 years being involved in technology in some form?</p><p>I’m excited for change on a regular basis. <strong>I don’t fear change, I chase it down and embrace it</strong>. I have to, because I have such a passion for teaching, and such an empathy to see my students succeed, that I feel I would fail them if I didn’t improve my own self.</p><p>As for that question that stumped me? I have no idea what my next, big goal would be. I joked that my next goal should be to figure out my next goal. I can’t see myself anywhere else in the near future than being an instructor at Turing. It’s exactly where I need to be at this time in my life and career.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96fe104d30bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Major Career Pivot]]></title>
            <link>https://iandouglas736.medium.com/a-major-career-pivot-c36256667ebe?source=rss-bd019600d679------2</link>
            <guid isPermaLink="false">https://medium.com/p/c36256667ebe</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[turing-school]]></category>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[teaching]]></category>
            <dc:creator><![CDATA[w. ian douglas]]></dc:creator>
            <pubDate>Fri, 11 Aug 2017 22:35:26 GMT</pubDate>
            <atom:updated>2017-08-11T22:35:26.469Z</atom:updated>
            <content:encoded><![CDATA[<p>I studied Computer Engineering (basically a combination of Computer Science and Electrical Engineering) in college in Canada, graduated in 1996. I began my career as a firmware developer after a brief stay at QNX doing technical support and “pre-sales engineering.” I enjoyed helping people and working on custom code for customers, but I didn’t spend 4 years learning the ins and outs of computers and hardware just to answer a support phone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*Ophp4F8QTVVAaH19vhKW9Q.gif" /></figure><p>While working as a firmware developer near Ottawa, Ontario, I learned web development, taught some friends, and we started a business doing basic web development projects and small-scale web hosting. I started technical blogging to share what I was up to, and started building open-source software.</p><p>In the spring of 2000 I responded to a job post for a technical teaching position at a private college in downtown Ottawa. I had been a paid tutor at my college and had a few years of development experience, so I was confident in sharing what I knew and helping others learn.</p><p>I made it through several stages of interviews, and the final interview step was to actually teach a class made up of other teachers at the college. No pressure, right? But the timing was off and they couldn’t get enough teachers together, and so the college put the final interviews on hold for all candidates. While I waited months for an update, I took a small vacation to Florida which led to a job offer in California. Mid-June 2000 I packed everything I owned and left Ottawa.</p><p>My first 6 months in California I agonized whether I’d made the right move: to a new country, to a state where I only knew 2 or 3 people, in a job with a bad manager. Had I made the wrong decision about that teaching role?</p><p>That Christmas, while visiting family back in Canada, I interviewed for new work back in Ottawa. But then the dot-com bust happened in early 2001. My California job was at a startup which processed credit reports, so I suddenly had all kinds of job security. While at this job, I met my future wife and one of my favorite dating stories was hanging out in a lab where she was learning PHP and MySQL and I was able to help some folks in the lab who had questions. It brought back the idea of being a teacher. Elizabeth went on to become a college teacher herself.</p><p>I continued to share knowledge while at subsequent jobs: I blogged more, I started going to meetups, I kept releasing open-source projects and trying to contribute to other projects.</p><p>And then I ended up at SendGrid. My quickest and closest colleagues at work were the Developer Relations team. <a href="https://twitter.com/thinkingserious">Elmer Thomas</a> and <a href="https://twitter.com/bwest">Brandon West</a> especially.</p><p>Wait, people actually get paid to travel, teach people things, and work on open-source?! Dream job!! But I was a Lead Engineer at SendGrid, and with a wife and kids at home I was happy to settle on “local” events, helping at conferences and hackathons and speaking at meetups. Don’t get me wrong, I like to travel, but there’s a reason why typical traveling DevRel reps only have an 18-month career span. I was content to “play” at Developer Relations.</p><p>This led to me doing more <a href="https://iandouglas.com/presentations/">talks</a> on non-SendGrid topics, I’m even scheduled to give a talk next week about using Agile in a startup environment for a small company in Boulder. I continue to find myself mentoring and teaching outside of work, usually for free. I had gone all-in on Linux in college (Slackware at the time), and the idea of open-source knowledge has never left me.</p><h3>Share what you know.</h3><p>A colleague at SendGrid suggested I get in touch with Jeff Casimir at the <a href="https://turing.io/">Turing School of Software and Design</a> in Denver. They were two blocks from the SendGrid office and needed tutors and mentors. Rachel Warbelow and I chatted for a while and I joined Turing as a volunteer mentor. My mentorship theme quickly hyper-focused on career counseling and technical interview preparation. Turing had enough technical mentors but they needed external help on resume prep and career readiness.</p><p>My hour or two per week involvement grew from over the next three years to where I am today: volunteering about 20 hours a week on top of a full-time job. I run a free weekly technical <a href="https://iandouglas.com/technical-coaching/interview-prep-class/">interview preparation class</a>. I have a free daily interview prep <a href="https://iandouglas.com/technical-coaching/interview-prep/?ref=medium">email series</a> you can join. I do several mock interviews for Turing students and do resume reviews on weekends. I do technical coaching to folks who need unbiased advice. I co-organize a <a href="http://coderdojodenver.com/">Denver-based CoderDojo class</a> to teach kids about coding. I also co-organize an 1,100 member <a href="https://meetup.com/BoulderPython">Python meetup group</a> in Boulder.</p><p>My current role is Developer Relations at <a href="https://getstream.io/get_started?ref=ian">Stream</a>. We’re a successful Techstars graduate company based in Boulder and Amsterdam providing an API for developers to quickly add activity feeds and social timelines into their applications. And I LOVE my job: all the cool stuff about DevRel like teaching and blogging and open-source and meetups, but almost none of the travel. (side note, <a href="https://angel.co/stream/jobs">we’re hiring</a>!)</p><p>I realized this spring that, while Turing continues to grow, my time is not scalable. And when I was tired and needed a break, I’d take a night off, catch up on some TV or a movie, and my first instinct every time is “man, I could be <em>helping</em> someone right now.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*xax3q9kNuuzRxJCm32USdQ.gif" /></figure><p>I began to reach out to other volunteer mentors to assist with mock interviews, and moved my one-on-one interview prep session to the Monday night group class. By sharing what I know, that advice can spread quicker through others.</p><h3>“I made a difference to that one.”</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*RHJVG5gKPgj-h4jkuETY2A.jpeg" /></figure><p>My passion for teaching runs in a similar vein. As a developer, we all have some type of desire to “change the world.” The chances we’ll ever work on technology that ACTUALLY changes the world is slim at best.</p><p>As a mentor I’ve offered career and interview advice to about 350 alumni at Turing alone, as well as some of the teaching staff. I’ve helped them understand coding challenges. I’ve consoled them after bad interviews. I’ve sent notes of encouragement to never give up. I’ve reviewed hundreds of revisions of resumes and coached them on technical interview tips.</p><p>I may never change the <em>actual</em> world we live in. The chances I create a piece of software that transforms everyday life for 7 billion people is so remote as to be laughable. Few, if any, people will remember my name 100 years from now.</p><p>But I CAN change the world for <strong>you</strong> if you’re interested in learning how technology can help YOU change something about <strong>your</strong> world. And maybe, just maybe, you’ll follow my lead and mentor and teach others, too.</p><p><strong>Share what you know</strong>, and we all win.</p><p>Make a difference in someone else’s world.</p><p>But do so out a <strong>genuine</strong> sense for just being <strong>helpful</strong> to someone else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*KCEUOGAa7eEG-nBO5BzclQ.jpeg" /></figure><h3>My Pivot</h3><p>Jeff Casimir and I had chatted very casually in the past about joining Turing as a teacher, but there were hurdles at the time that made it impossible to join. This summer, though, Jeff surprised me with a message one day asking what it would take to join Turing and become a full-time teacher. I would later tell Jeff that my initial reaction was 50% imposter syndrome (could I actually do this full-time?) and 50% “it’s about freakin’ time you asked.”</p><p>I’m excited to start a new career as a full-time instructor at Turing beginning in October, 2017. I’ve got 21 years of experience to share, stories to tell, and laughable amounts of what NOT to do in certain scenarios. I’d be lying if I said imposter syndrome wasn’t nagging at me, though, or that I wasn’t scared at the enormity of this career change.</p><p>I’m <strong>enormously</strong> grateful to Jeff and the team at Turing for putting their trust in me, and I’m looking forward to the next phase of life as I step away from full time software development.</p><p>And to the alumni of Turing who are sending in messages of support, <strong>much love to all of you</strong>, especially those leaving these kinds of messages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*JzMT0-AqUgsmwEWbr1nuiQ.png" /><figcaption>LOL</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/230/1*AQQ35PhoyxsMeKrq-0U72w.png" /><figcaption>I’m gonna say yeah, but don’t tell Jeff :)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*6olQB-hFQ4UJdD3KFUwEbA.png" /><figcaption>I’m sure they’d let you!</figcaption></figure><p>So what about Stream, you ask? We’re still working out the details, but all sides are hopeful that I can continue to contribute to Stream’s success in some way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c36256667ebe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview Pro-Tip: Be a user, not just a candidate]]></title>
            <link>https://iandouglas736.medium.com/interview-pro-tip-be-a-user-not-just-a-candidate-687a7b1210f4?source=rss-bd019600d679------2</link>
            <guid isPermaLink="false">https://medium.com/p/687a7b1210f4</guid>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[w. ian douglas]]></dc:creator>
            <pubDate>Mon, 26 Jun 2017 19:46:11 GMT</pubDate>
            <atom:updated>2017-06-26T19:46:11.864Z</atom:updated>
            <content:encoded><![CDATA[<p>I do career mentorship for a 7-month code school in Denver: <a href="https://turing.io/">The Turing School of Software &amp; Design</a>. Their programs are broken into four 6-week modules with a small break in between. One of my favorite interview preparation techniques is about <strong>identifying companies where they’d like to apply for work</strong> upon graduation.</p><p>Certainly, knowing the industries and companies where you’d like to work is vital. But <strong>how do you stand out</strong> from the hundreds or thousands of other applicants trying to get that same job?</p><p>As you identify those companies, find a way to use their product, SDK, library, tool, or even mash-up some of their public data, into your portfolio of projects.</p><p>Now <strong>you’re not just a candidate</strong>, you’re a user. When you reach out to the company to do your usual networking, <strong>you’re a customer</strong>. You’re not some random person at a meetup, you’re someone whose feedback and questions should be <strong>given more attention and respect</strong>. You can speak directly to their “developer experience”. Companies love feedback, and are far more likely to return calls and answer questions from customers.</p><p><strong>Want more tips and ideas?</strong> I wrote <a href="https://iandouglas.com/technical-coaching/interview-prep/?ref=medium">a daily email series for technical interview preparation</a> by learning to think like an interviewer. Learn how to analyze questions to give more effective answers. Give yourself an edge and get ahead.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=687a7b1210f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Thirty (or so) days of Technical Interview Preparation via Email]]></title>
            <link>https://iandouglas736.medium.com/thirty-or-so-days-of-technical-interview-preparation-via-email-75c83d165c54?source=rss-bd019600d679------2</link>
            <guid isPermaLink="false">https://medium.com/p/75c83d165c54</guid>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[technical-interview]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[mentoring]]></category>
            <category><![CDATA[coaching]]></category>
            <dc:creator><![CDATA[w. ian douglas]]></dc:creator>
            <pubDate>Tue, 30 May 2017 05:00:31 GMT</pubDate>
            <atom:updated>2017-05-31T19:41:49.897Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C4jwcRah-mWmsVmV3WL3_A.jpeg" /></figure><p>Tech interviews are scary, even for seasoned veteran developers. <strong>They’re even worse for entry-level developers — especially those from code schools.</strong> What should you expect? How do you prepare? Should I bring a laptop? What’s the real goal of a technical interview? And why are they even asking me these kinds of questions?</p><p>The last 14 years of my 21-year software engineering career have found me on interview teams, or as a direct hiring manager or decision maker. Several thousands of resumes screened. Hundreds of technical interviews conducted, ranging from interns to VP of Engineering candidates. Dozens of interesting interview questions created and refined.</p><p>I’ve also actively helped hundreds of code school graduates with resume and cover letter creation, and interview preparation. I conduct mock interviews, teach negotiation tactics, explain how to evaluate benefits and equity in offers, and more.</p><p>I wanted to start reaching a wider audience with technical interview coaching, and created a series of emails to help you prepare for your first (or 100th) technical interview. Why are <em>these</em> emails different from other interview prep material online? <strong>Because I’m going to teach you how to think like an interviewer.</strong></p><p>You can subscribe here:<br><a href="https://iandouglas.com/technical-coaching/interview-prep/">https://iandouglas.com/technical-coaching/interview-prep/</a></p><p>There are plenty of articles on the internet instructing you how to prepare for a technical interview. It’s all about data structures and algorithms, right? Not as many articles help you understand WHY you should study certain topics or teach you about soft skills you need to succeed. I’ve rarely seen any that help you understand <strong>why the interviewer is asking certain questions or what they listen for in your answer</strong>.</p><p>You’ll receive an email in your inbox every day for the next 30+ days with one or more example interview questions. Some emails explore the motivation behind the questions. Others cover common variations of technical questions you can expect to hear. Some will cover my observation of trends in the industry and what kinds of things companies care about more based on the size and maturity of the business.</p><p><strong>Get inside the head of your interviewer, and subscribe</strong> to the series at <a href="https://iandouglas.com/technical-coaching/interview-prep/">https://iandouglas.com/technical-coaching/interview-prep/</a></p><p>I also want your feedback. Reply to any message in the series to reach my inbox with feedback or questions, or additional topics you’d like me to cover.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75c83d165c54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Examining Decentralized Social Networks]]></title>
            <link>https://iandouglas736.medium.com/examining-decentralized-social-networks-a7351f631826?source=rss-bd019600d679------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7351f631826</guid>
            <category><![CDATA[distributed]]></category>
            <category><![CDATA[social-network]]></category>
            <category><![CDATA[decentralized]]></category>
            <dc:creator><![CDATA[w. ian douglas]]></dc:creator>
            <pubDate>Wed, 03 May 2017 19:37:58 GMT</pubDate>
            <atom:updated>2017-05-03T19:38:01.834Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*N5mX28lS133dBd2J." /></figure><p>Most companies who create a social network do so with the end goal of collecting information, interests and habits of their users in order to monetize that data (usually through advertising). They guard this data heavily and many of the largest social networks are trusted enough to be Identity Providers for OAuth-based authentication and single-sign-on mechanisms such as “Log In with Facebook/Twitter/Linkedin/etc”.</p><p>We have many customers with production apps who use Stream to help develop social applications, and we thought it would be interesting to dig into four “decentralized” or “distributed” social networks/platforms (who have not been customers of Stream) to see what makes them tick. We’ll try to assess what is good or bad about the underlying architecture and take a look at why they’re succeeding or failing.</p><h4>Backstory and History</h4><p>“Social networks” have been around a lot longer than many folks realize. My own first experience was a “bulletin board system” back in the 80’s using a dial-up modem where you registered on a computer and could interact with, and send messages to other users on that system. This expanded into more mainstream email accounts and ushered in the era of AOL, CompuServe and others. These spun off into other community-based web sites which launched ideas into larger and larger platforms such as Facebook, Twitter, Instagram, Google+ and so on.</p><p>These platforms are “centralized” in the sense that there is only one entity responsible for your account access, and managing access to any content you choose to upload and share privately or publicly on their platform. Many users aren’t crazy at the idea of large entities controlling access to their content, which has resulting in many viral <a href="http://gawker.com/5963225/that-facebook-copyright-thing-is-meaningless-and-you-should-stop-sharing-it">ownership claims</a> that get recycled from time to time. It’s a valid concern, especially when the platform isn’t 100% clear on how they’ll use your content for additional monetization efforts.</p><p>Over time, the idea of ownership and granular control on who can see and use your content has spawned ever-growing interest in a decentralized platform where you can share your data.</p><p>One of the biggest contributors to decentralized platforms points back to StatusNet, based in Montreal Canada, which started as a microblogging platform back in 2007. Their work was later donated to the Free Software Foundation, with contributions from other parties later became <a href="https://gnu.io/social/">GNU Social</a>, while StatusNet Inc (the company) later migrated to <a href="http://pump.io/">pump.io</a>. StatusNet Inc also developed <a href="https://en.wikipedia.org/wiki/OStatus">OStatus</a> as a combination of protocols for social sharing; both GNU Social and OStatus were the inspiration for <a href="https://mastodon.social/">Mastodon</a>.</p><h4>GNU Social</h4><p>GNU Social began in 2010 as a spin-off project from a music community and later merged into StatusNet which adopted the GNU Social name in 2013. It has a very large list of federated servers (found on other links at <a href="https://gnu.io/social/try/">gnu.io</a>) and allow members to post content and share that content easily across other systems using a pub/sub model.</p><p>GNU Social at its roots is a full <a href="https://git.gnu.io/gnu/gnu-social">open-source PHP project</a> that encourages new contributions. They support a rich plugin system allowing users to build up a server with exactly the features they would like to support their community. Several supporting projects exist on <a href="https://git.gnu.io/explore/projects">their GitLab page</a> outlining plugins and features and alternate user interfaces.</p><h4>Mastodon</h4><p>Mastodon is a mash-up of several protocols and platforms, but largely based on the idea of compatibility with GNU Social:</p><blockquote>Mastodon is a re-implementation of the GNU Social codebase, which itself is an implementation of the OStatus protocol, originally forking from the GNU FM project and later merging with the StatusNet and FreeSocial projects, from the same people behind Identi.ca, which was later folded into pump.io, which uses the ActivityStreams spec along with protocols like PubSubHubBub, Salmon, WebFinger, and Atom syndication to deliver a federated, open-source Twitter-like experience for the masses.<br> (Source: hackernoon.com)</blockquote><p>Mastodon started out as a Ruby on Rails rewrite of GNU Social. Its core UI, written in React and Redux, is reminiscent of TweetDeck. The platform offers some more powerful features than Twitter but also some quirks that perhaps users weren’t expecting. Certainly, Mastodon has expanded on Twitter’s platform by allowing longer messages and other features, and promises to be advertising-free. No ads — where have we heard that before? Ello, App.net, Diaspora, Path, and more, some of which either charged members to use the platform or moved to “freemium” models.</p><p>Mastodon maintains <a href="https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/List-of-Mastodon-instances.md">a large list of instances</a> where you can register an account, and Eugin Rochko has authored <a href="https://medium.com/@Gargron/scaling-mastodon-1becde463090">a post about his challenges scaling</a> the platform. As of late April, the author of Mastodon claims almost half a million users across over 1,200 Mastodon instances running around the world.</p><h4>Steemit</h4><p><a href="https://steemit.com/">Steemit</a> is a “distributed social network” written mostly in C++ which rewards its users with a cyber-currency called Steem for posting and curating quality content. Based on modern blockchain technology, their open-source platform allows for verifiable and indisputable origin of content, which is great if you really want people to know you authored something, but most blockchain instances do not allow for deletion of content so you lose granularity of control to gain authenticity. Also, since every Steem client has access to everything on the blockchain, your posts/votes/comments are effectively public unless you encrypt them for <a href="https://steemit.com/steem/@charlieshrem/announcing-steemmsg-encrypted-private-messages-on-the-steem-blockchain">SteemMsg</a>.</p><p>You can certainly spin up your own instance, but ultimately all data will still be shared on the blockchain. It appears the only way to have a truly “private” Seemit instance would be to encrypt all transmissions and control a decryption key within client software.</p><h4>Synereo</h4><p>A similar blockchain-based social network, <a href="http://www.synereo.com/">Synereo</a>, has a similar model to Steemit, but their target audience appears to be people who want to monetize their content authorship and reward people who help promote the content. Their invite-only platform is written in mostly Scala and some Java. Again, it focuses on the authenticity of who authored the content, but the content is still shared across the entire blockchain. Their project also exists on GitHub with instructions on setting up your own node, but with warnings that it’s experimental in nature.</p><h4>Where is your Content, and Who are you Really?</h4><p>A primary difference between blockchain networks and those using something like GNU Social is where your content lives. If you register on a Mastodon site, your content lives at that site, but is distributed via pub/sub to other sites where users follow your account. Just because a site is part of the larger “fediverse” of Mastodon, that one site still controls your content every bit as much as Facebook, Twitter, Instagram, etc.. And while each Mastodon partner site has to conform to the overall Mastodon statement of purpose (no ads, etc), they may not be restricted in how they use your data. In contrast, in a blockchain system your content is distributed to every other node using that blockchain whether someone at that node wants your content or not.</p><p>A common confusion to the rush of new Mastodon users (and I’m sure other users on GNU Social sites) is that you register on only one site. This is good because it means that that one site is the only one controlling access to your data, but it’s a lot like registering an email address: registering and reserving your username on one Mastodon site (for example) does not reserve that name on any other Mastodon site.</p><p>In order to use at-mentions in a message to flag another user, you have to know which other site they registered on. When <a href="https://mastodon.social/">mastodon.social</a> shut down registrations due to scalability issues, I registered an account on <a href="https://mastodon.cloud/">mastodon.cloud</a> instead. If you also registered on the “.cloud” domain and write a message mentioning “@iandouglas”, I will get a notification. But you register on the “.social” domain and mention “@iandouglas”, it will ping some other user named “@iandouglas” on that platform (which is not me). So if you’re on any other Mastodon node and want to ping me in a message when my account is at mastodon.cloud, you need to mention “@iandouglas@mastodon.social” in your message.</p><p>This is a serious drawback to commercial groups or high-profile users like celebrities, because not reserving your business name or celebrity name on one platform runs the risk of infringement and other abuse not unlike the rush to reserve your company’s name whenever a new top-level domain (TLD) is released so you can get YourBusinessName.newTLDsuffix to match your .com, .org, .net, .io, and so on. I imagine some legal teams are lining up to take on legal claims from cyber-squatters who register names of big companies.</p><h4>Other Pros and Cons of a Decentralized Platform</h4><p>A positive benefit to a decentralized system such as GNU Social or Mastodon is the ability to launch your own version of the software on a private system for you and your friends. This means you do not have to worry about sharing that content outside of your server. Blockchain-based social networks can ensure authenticity of who authored some content but keeping your data private would rely on a large network of shared encryption keys.</p><p>There are other benefits to decentralized networks, certainly, and it gives end users a lot more flexibility for who controls their content. Unlike a large entity like Facebook or Twitter, whose users love to hate for questioning the “ownership” of content, unless you’re running your own decentralized server, ultimately you’re still handing over your content to an unknown entity who may not have the same scruples around data security that the larger social networks have had to put in place to protect your data. In the case of blockchain-based groups, it can be difficult or impossible to ever delete your content.</p><p>Since each GNU Social or Mastodon site can also establish their own features and rules (or lack of rules), there’s no one entity to control or censor your content. This may be great for those who want more freedom in their writing, but there are other readers who may not want to read unmoderated content on a timeline feed.</p><h4>Conclusions</h4><p>Should you build a traditional social application, or join a decentralized network to expand the reach and capabilities of your users? That architecture decision is ultimately yours to make, but there are some great options out there based on both GNU Social and blockchain technologies. Decentralized or distributed social platforms are a growing trend and there are pros and cons to the two different approaches we discussed above.</p><p>At Stream, we make building social apps and activity feeds a quick and easy process, but there are lots of interesting ways to store the core activity data within your back-end application. Regardless of how you choose to build your social application, Stream offers a convenient, scalable and highly-available solution for applications of all sizes. You can try things out on our <a href="https://getstream.io/get_started/">interactive tutorial and have a prototype going in minutes</a>. Stream takes the guesswork out of follow relationships and offers aggregated and notification feeds, ranked feeds, and recommendation feeds based on machine learning of activity analytics and other data points. We can’t wait to see what you build with Stream!</p><p><em>Originally published at </em><a href="https://getstream.io/blog/examining-decentralized-social-networks/"><em>The Stream Blog</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7351f631826" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Performant API using Go and Cassandra]]></title>
            <link>https://iandouglas736.medium.com/building-a-performant-api-using-go-and-cassandra-b7b11b7d58?source=rss-bd019600d679------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7b11b7d58</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[w. ian douglas]]></dc:creator>
            <pubDate>Wed, 01 Feb 2017 23:29:54 GMT</pubDate>
            <atom:updated>2017-02-01T23:29:59.094Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*EwVOyg7IheRO4aVe.png" /></figure><h4>Introduction</h4><p>Software performance is critical to a SaaS company like <a href="https://getstream.io/">Stream</a> and while the majority of our infrastructure is written in Python, we are actively porting portions of our code base to Go.</p><p>Stream is an API for building scalable feeds and now handles over 20 billion feed updates a month. While Python has been fast enough for many things, the additional speed and efficiency of Go is becoming important to us. (If you’ve never tried Stream, here’s a <a href="https://getstream.io/get_started/?utm_source=blog&amp;utm_campaign=growth&amp;utm_medium=go-api#intro">5 minute interactive tutorial</a>)</p><p>This migration from other scripting languages like Python to Go is becoming pretty commonplace in our industry. Before Stream I worked as a lead engineer at SendGrid for 4 years and the last 18 months was spent replacing sluggish code from Ruby and Python, and writing internal and external APIs, in more performant Go.</p><p>This tutorial will teach you how to build a RESTful API using Go and Cassandra. Cassandra is a NoSQL database that automatically shards your data across a cluster of machines. Here at Stream we use Cassandra for the storage of news feeds and activity streams. it’s performance, linear scalability and reliability make it the #1 datastore for many large platforms such as Netflix, GitHub, Reddit, Instagram, Sony, Coursera, Spotify, and eBay.</p><p>The source code for this tutorial can be found on our <a href="https://github.com/GetStream/Stream-Example-Go-Cassandra-API/">GitHub repository</a>.</p><h4>Step 1 — Cassandra</h4><p>By far, the easiest way to get Cassandra installed and running is to use the <a href="https://github.com/pcmanus/ccm">Cassandra Cluster Management script</a>, and we’ll use <a href="http://brew.sh/">homebrew</a> for setting up tooling on a Mac; setup on Linux should be very similar but your mileage may vary on Windows platforms. Running “brew install ccm” will get you started, and we’ll also need a Java environment, which is bundled in the “maven” package.</p><h4>A. Cassandra Setup</h4><pre>$ brew install ccm maven</pre><p>To query Cassandra from the command line we need a tool called cqlsh. You can easily install the cqlsh command with pip:</p><pre>$ pip install cqlsh==5.0.3</pre><p>To begin, we need to install Cassandra and create a cluster. The following command downloads and install Cassandra v3.9 and creates a cluster named streamdemoapi</p><pre>$ ccm create -v 3.9 streamdemoapi</pre><p>Next we need to add one or more nodes to our cluster. For the tutorial we only need a single node:</p><pre>$ ccm populate -n 1<br>$ ccm start</pre><p>You can verify the cluster booted correctly by running ccm status.</p><pre>$ ccm status</pre><p>Finally we create a keyspace with single-node replication. If we had set up multiple nodes in the previous step, we could specify how many nodes we wanted to replicate data onto.</p><pre>$ echo &quot;CREATE KEYSPACE streamdemoapi WITH \<br>replication = {&#39;class&#39;: &#39;SimpleStrategy&#39;, &#39;replication_factor&#39; : 1};&quot; | cqlsh --cqlversion 3.4.2</pre><p>Congratulations, you now have a Cassandra cluster + keyspace up and running.</p><p>Note: For a production Cassandra setup there are more things to keep in mind: We recommend starting at Datastax and browsing <a href="https://academy.datastax.com/tutorials?field_topics_tid=714">their tutorial series</a> on using Cassandra.</p><h4>B. Cassandra Schema</h4><p>We will define two tables to hold our data for users and messages. We recommend using UUIDs for unique resource identifiers when sending an activity to Stream, so we’ve used UUIDs as our primary key in our table structures to identify each message and user in our system.</p><pre>$ echo &quot;<br>use streamdemoapi;<br>create table messages (<br>id UUID,<br>user_id UUID,<br>Message text,<br>PRIMARY KEY(id)<br>);&quot; | cqlsh --cqlversion 3.4.2</pre><p>Our user table will contain some simple data about each person using our application, including their first name, last name, age, city and email address.</p><pre>$ echo &quot;<br>use streamdemoapi;<br>CREATE TABLE users (<br>id UUID,<br>firstname text,<br>lastname text,<br>age int,<br>email text,<br>city text,<br>PRIMARY KEY (id)<br>);&quot; | cqlsh --cqlversion 3.4.2</pre><h4>Step 2 — Go</h4><p>Installing Go on a Mac is super easy with homebrew. Installation instructions for Linux and Windows can be found at <a href="https://golang.org/dl/">golang.org</a>. The current version as of this writing is Go 1.7.4.</p><h4>A. Go setup</h4><p>Let’s install the binaries and standard library for Go on our Mac:</p><pre>$ brew install go</pre><p>With the binary installed, we will need to configure the “GOPATH” folder where we’ll install third-party Go libraries and packages. Within your terminal shell configuration (for example, .bashrc or .zshrc) we will add some new environment settings:</p><pre>export GOPATH=$HOME/golang<br>export GOROOT=/usr/local/opt/go/libexec</pre><p>The GOROOT setting tells our shell where to find Go binaries and the standard libraries. This may not be required on your system if you’re using Go 1.7 or better, as it can find the path on its own if the main “go” binary itself in your PATH.</p><p>Restart your shell, or source your shell configuration file, and then create this new path:</p><pre>$ mkdir $HOME/golang</pre><h4>B. Go Dependencies</h4><p>Go can be very peculiar about dependency management and the Golang team recommends “vendoring” your dependencies within the same folder as your project source code to ensure you don’t have to worry about running “go get” in the future and ending up with a newer version of a library than your code can utilize. Our tutorial will install all packages within our GOPATH for simplicity.</p><p>With our GOPATH defined above, we can install third-party Go packages, such as the Cassandra client, by running the “go get” command followed by the origin of the package. To install the Cassandra driver for our project, we’ll issue the following command:</p><pre>$ go get github.com/gocql/gocql</pre><p>You will find the new package installed under your home folder, in the “golang” folder we created above, in a subfolder called “src”. In that src folder, you’ll see another folder for github.com and so on for each of the packages you install.</p><p>For our project we’ll also need the following libraries which we’ll describe later in this tutorial:</p><pre>$ go get github.com/gorilla/mux<br>$ go get github.com/GetStream/stream-go</pre><p>If you are creating a Go application that will not have subpackages, you can develop the code anywhere on your filesystem. However, since this application (and most other apps you will develop) will use subpackages, your code must live in your GOPATH folder.</p><p>To make sure you’re in the correct folder to begin your code, navigate to your GOPATH/src folder with this command:</p><pre>$ cd $GOPATH/src</pre><p>Since you will have your code in a repository somewhere, you will place your project code in a folder based on your username and project name. For example, if your username on GitHub was johnsmith and your project was awesomeproject, then you would create your project under the following path:</p><pre>$ mkdir $GOPATH/src/github.com/johnsmith/awesomeproject<br>$ cd $GOPATH/src/github.com/johnsmith/awesomeproject</pre><p>Technically, it doesn’t matter what this path is, but this is a common standard employed by other Go developers, so it will cause fewer problems if you conform to this standard.</p><p>At this point, you can start writing your code!</p><h4>Step 3 — Your first REST endpoint</h4><p>When we’re all finished with this tutorial, our API contract will look something like this:</p><blockquote>GET / — heartbeat check if our API is online</blockquote><blockquote>GET /users — fetch all users from the database<br> GET /users/UUID — fetch an individual user from the database<br> POST /users/new — create a new user</blockquote><blockquote>GET /messages — fetch all messages from Stream (with the database as a backup)<br> GET /messages/UUID — fetch an individual message from the database<br> POST /messages/new — create a new message</blockquote><p>One big question faced by a lot of Go API developers is whether to use a third-party web framework or to use the standard libraries which ship with Go. In my experience building APIs with both standard libraries and third-party frameworks, I think it’s really a personal call. Certainly, rewriting advanced routing rules and dispatch/middleware handlers every time you create an application with the standard libraries is time-consuming, but using third-party frameworks can often place constraints on your code where you must do things “their” way. The standard library is certainly more than capable of managing a simple API setup, but sometimes it’s nice to have well-tested third-party code that make it easier and quicker to get started.</p><p>In our example application, we opted to use the popular <a href="https://github.com/gorilla/mux">gorilla/mux project</a> to build our API.</p><p>Let’s start with the heartbeat endpoint.</p><p><strong>Go #protip:</strong> Good project structure in Go means as little logic in your applications’ /main.go starting point, and breaking down other logic/branches into subfolders to separate your code’s concerns, so code we write after this part of the tutorial will all go into subfolders, which creates subpackages.</p><p>The first line of your Go script is the name of your package, and Go will always expect the root level of your project to be a package called “main”. We must tell our Go script which other libraries we intend to use with the “import” command. To get started with gorilla/mux and a basic API endpoint for a status check (also called a “heartbeat”). Create a file called main.go at the base of your project folder (ie, johnsmith/awesomeproject/main.go) and add the following code:</p><pre>package main<br><br>import (<br>  &quot;net/http&quot;<br>  &quot;log&quot;<br>  &quot;encoding/json&quot;<br>  &quot;github.com/gorilla/mux&quot;<br>)</pre><p>In order for gorilla/mux to return any payload, we must define the exact structure of the data. In our example we will send back a string for “status” and an integer for a status code. For example, if our API is running successfully, we could send back a status of “OK” and a code of 200, which is a typical HTTP response for a successful web connection.</p><pre>type heartbeatResponse struct {<br>  Status string `json:&quot;status&quot;`<br>  Code int `json:&quot;code&quot;`<br>}</pre><p>The `json:”status”` portion of the field definition above will tell our JSON-encoder to rename the “Status” and “Code” fields during the encoding process to their lowercase versions.</p><p>Next, we define our “main” function, which is a reserved name in Go for where your code will begin. Within our main function, we need to set up a new gorilla/mux router to handle our API endpoints according to the contract we described above. We can add a new API route after our router is declared, and give it the name of another function to execute when a request is made for that endpoint. In this case, we’ll call a new function called heartbeat:</p><pre>func main() {<br>  router := mux.NewRouter().StrictSlash(true)<br>  router.HandleFunc(&quot;/&quot;, heartbeat)<br>  log.Fatal(http.ListenAndServe(&quot;:8080&quot;, router))<br>}</pre><p>The last line of code tells Go to listen on port 8080, which will also log any errors returned and throw a fatal error to crash our application.</p><p>Finally, we must declare our heartbeat() function for the “/” endpoint, so we’ll add code this after our main() function:</p><pre>func heartbeat(w http.ResponseWriter, r *http.Request) {<br>  json.NewEncoder(w).Encode(heartbeatResponse{Status: &quot;OK&quot;, Code: 200})<br>}</pre><p>The handler code inside heartbeat() tells gorilla/mux to use a JSON encoder on our output handle (our http.ResponseWriter variable simply called “w”), and encode our data structure that we defined above our main() function which we called heartbeatResponse, and to set our “OK” status string, and our status code of 200, indicating our API is running properly.</p><p>Now we save our code, and we can execute it in our terminal by running the following command:</p><pre>$ go run main.go</pre><p>If there are no errors, you won’t see any output, and the program will appear to “hang” but it’s actually running in the background, listening on port 8080. To test this, open your browser and go to the following address:</p><p><a href="http://localhost:8080/">http://localhost:8080/</a></p><p>If all goes well, you should see some JSON text in your browser which says:</p><pre>{“status”: “OK”, “code”: 200}</pre><p>To stop the API from running, you can press CTRL-C to kill the Go application.</p><p>Congratulations — you’ve created a Go-powered API! It’s not terribly useful yet, though, so we can continue adding code, such as the remaining routes for our API contract for getting or creating users and messages. In our final /main.go code, linked below, we’ll also connect to our local Cassandra instance and verify our Stream credentials allow us to connect.</p><p>Final Source: <a href="https://github.com/GetStream/Stream-Example-Go-Cassandra-API/blob/master/main.go">/main.go</a></p><h4>Step 4 — Using Cassandra in Go</h4><p><strong>Go #protip:</strong> When you import submodules in Go, any packages containing a method called init() will have all of those init() functions called immediately before the process’ main() function. The caution here is that if you have several submodules with init() functions declared, there is no guarantee of run order so you must ensure you don’t inadvertently impose a required order by having mixed dependencies. If you must have these initializations happen in a specific order, it’s best to declare an exported method in each submodule and call them explicitly from your process’ main() function.</p><p>Because the Cassandra code will live in a subfolder called Cassandra, it becomes a subpackage to our primary Go code, and therefore must have a new package name, declared on the first line of our code. Next, we will import the GoCQL library package. (we also import the “fmt” standard library to print a message when we are connected to Cassandra)</p><p>Create a file Cassandra/main.go and add this code:</p><pre>package Cassandra<br><br>import (<br>  &quot;github.com/gocql/gocql&quot;<br>  &quot;fmt&quot;<br>)</pre><p>In order to use our Cassandra connection elsewhere in our code, we will declare a variable called Session. To use a subpackage variable in other code outside of this subfolder, we must name the variable with the first letter as an uppercase letter. A variable named “session” (all lowercase) will not be visible to other packages.</p><pre>var Session *gocql.Session</pre><p>Next, we will declare our init() function which will run as soon as our API code executes (but before our application’s /main.go main() function is run):</p><pre>func init() {<br>  var err error<br><br>  cluster := gocql.NewCluster(&quot;127.0.0.1&quot;)<br>  cluster.Keyspace = &quot;streamdemoapi&quot;<br>  Session, err = cluster.CreateSession()<br>  if err != nil {<br>    panic(err)<br>  }<br>  fmt.Println(&quot;cassandra init done&quot;)<br>}</pre><p>To connect to Cassandra, we use the GoSQL NewCluster() method and pass an IP address or hostname and store that connection in a variable called “cluster”. Next, we declare which cluster name we wish to use; in this case we define “streamdemoapi” as our cluster name. Finally, we create a session on the cluster and assign that to our exportable Session variable.</p><p>The <a href="https://github.com/gocql/gocql">GoCQL project</a> makes interfacing with Go super easy, and many queries can be written just like common SQL for selecting or inserting data into a database, which we’ll show in the next submodule.</p><p>The last steps are to add one more import to our application’s /main.go (not in Cassandra/main.go):</p><pre>package main<br><br>import (<br>  ...<br>  &quot;github.com/username/projectname/Cassandra&quot;<br>  ...<br>)</pre><p>And finally we tell our application’s /main.go main() function to defer closing our Cassandra connection:</p><pre>func main() {<br>  CassandraSession := Cassandra.Session<br>  defer CassandraSession.Close()<br><br>  router := mux.NewRouter().StrictSlash(true)<br>  ...<br>}</pre><p>The first line will utilize our Cassandra session from our subpackage and store that in a new local variable. The defer line tells Go to disconnect from Cassandra if the application’s /main.go main() function exits for any reason.</p><p>You can verify everything worked by running:</p><pre>$ go run main.go</pre><p>And you should see a message in your terminal that the Cassandra initialization is done.</p><p>Final source: <a href="https://github.com/GetStream/Stream-Example-Go-Cassandra-API/blob/master/Cassandra/main.go">Cassandra/main.go</a></p><h4>Step 5 — Creating and Reading Users</h4><h4>A. Creating Users</h4><p>To create or fetch user data from Cassandra, we create a sub-package (and folder) called Users and have our data structures and logic split into separate files within that folder. All files within this folder must also have a matching package declaration that is different from all other subpackages in our application.</p><pre>package Users</pre><p>Create a file, Users/structs.go, to contain our data structures, and Users/processing.go for handling form data. You can refer to our GitHub source for the exact code, links are below, and we’ll describe these in detail later. To simplify getting started right now:</p><p>&gt;&gt; Copy <a href="https://raw.githubusercontent.com/GetStream/Stream-Example-Go-Cassandra-API/master/Users/structs.go">this file</a> to your project as Users/structs.go<br> &gt;&gt; Copy <a href="https://raw.githubusercontent.com/GetStream/Stream-Example-Go-Cassandra-API/master/Users/processing.go">this file</a> to your project as Users/processing.go</p><p>To add data to Cassandra, we will create a file called Users/post.go to handle our POST operation on our API.</p><p>In our imports, we will include a reference to our Cassandra subpackage</p><pre>package Users<br><br>import (<br>&quot;net/http&quot;<br>&quot;github.com/gocql/gocql&quot;<br>&quot;encoding/json&quot;<br>&quot;github.com/username/projectname/Cassandra&quot;<br>&quot;fmt&quot;<br>)</pre><p>We will make a function called Post() which take a request and response variable from gorilla/mux. Let’s explain what happens within the function:</p><pre>func Post(w http.ResponseWriter, r *http.Request) {<br>  var errs []string<br>  var gocqlUuid gocql.UUID<br><br>  // FormToUser() is included in Users/processing.go<br>  // we will describe this later<br>  user, errs := FormToUser(r)<br><br>  // have we created a user correctly<br>  var created bool = false<br><br>  // if we had no errors from FormToUser, we will<br>  // attempt to save our data to Cassandra<br>  if len(errs) == 0 {<br>    fmt.Println(&quot;creating a new user&quot;)<br><br>    // generate a unique UUID for this user<br>    gocqlUuid = gocql.TimeUUID()<br><br>    // write data to Cassandra<br>    if err := Cassandra.Session.Query(`<br>      INSERT INTO users (id, firstname, lastname, email, city, age) VALUES (?, ?, ?, ?, ?, ?)`,<br>      gocqlUuid, user.FirstName, user.LastName, user.Email, user.City, user.Age).Exec(); err != nil {<br>      errs = append(errs, err.Error())<br>    } else {<br>      created = true<br>    }<br>  }<br><br>  // depending on whether we created the user, return the<br>  // resource ID in a JSON payload, or return our errors<br>  if created {<br>    fmt.Println(&quot;user_id&quot;, gocqlUuid)<br>    json.NewEncoder(w).Encode(NewUserResponse{ID: gocqlUuid})<br>  } else {<br>    fmt.Println(&quot;errors&quot;, errs)<br>    json.NewEncoder(w).Encode(ErrorResponse{Errors: errs})<br>  }<br>}</pre><p>Next, if our application’s main.go, we need to add the Users subpackage to our imports and add a new REST endpoint to our gorilla/mux router to call this Post() method:</p><pre>import (<br>  ...<br>  &quot;github.com/username/projectname/Cassandra&quot;<br>  &quot;github.com/username/projectname/Users&quot;<br>  ...<br>)<br><br>func main() {<br>  ...<br>  router := mux.NewRouter().StrictSlash(true)<br>  router.HandleFunc(&quot;/&quot;, Heartbeat)<br>  router.HandleFunc(&quot;/users/new&quot;, Users.Post)<br>  ...<br>}</pre><h4>Testing our new endpoint</h4><p>&gt;&gt;&gt; Curl example of posting to the User endpoint</p><pre>curl -X POST \<br>-H &quot;Content-Type: application/x-www-form-urlencoded&quot; \<br>-d &#39;firstname=Ian&amp;lastname=Douglas&amp;city=Boulder&amp;email=ian@getstream.io&amp;age=42&#39; \<br>&quot;http://localhost:8080/users/new&quot;</pre><p>The response you get should look similar to:</p><pre>{&quot;id&quot;:&quot;75a243c1-e356-11e6-81c2-c4b301bb0fa9&quot;}</pre><p>Now that we’ve tested that our POST operation works, let’s rewind and describe what Users/processing.go is actually doing.</p><p>At a high level, gorilla/mux provides a method on your request interface called PostFormValue which takes a string parameter and returns a string of data (or empty string if the parameter was not present in the form data). We check the string length for each parameter that we require and if the length is 0 we push an error onto an array and return those errors to the user. We cycle through all form variables we expect to find and also validate that the age parameter is an integer.</p><p>Let’s look at this closer:</p><p>Our Users/processing.go file is part of our Users subpackage, and imports a few standard libraries.</p><pre>package Users<br><br>import (<br>  &quot;net/http&quot;<br>  &quot;strconv&quot;<br>)</pre><p>Next, we have a function which allows us to append a string onto an existing array of strings. Go does not have a built-in mechanism for this, so we wrote our own:</p><pre>func appendError(errs []string, errStr string) ([]string) {<br>  if len(errStr) &gt; 0 { <br>    errs = append(errs, errStr)<br>  }<br>  return errs<br>}</pre><p>Now we’ll define a function which will take our request interface, and a string, and return the field data or an error in one of two return positions. As mentioned above, gorilla/mux has a PostFormValue() method defined for us to fetch form data from an HTTP request.</p><pre>func processFormField(r *http.Request, field string) (string, string) {<br>  fieldData := r.PostFormValue(field)<br>  if len(fieldData) == 0 {<br>    return &quot;&quot;, &quot;Missing &#39;&quot; + field + &quot;&#39; parameter, cannot continue&quot;<br>  }<br>  return fieldData, &quot;&quot;<br>}</pre><p>Finally, we have our code that cycles through each of the fields we deem to be “required” fields on our form data:</p><pre>func FormToUser(r *http.Request) (User, []string) {<br>  var user User<br>  var errStr, ageStr string<br>  var errs []string<br>  var err error<br><br>  user.FirstName, errStr = processFormField(r, &quot;firstname&quot;)<br>  errs = appendError(errs, errStr)<br>  user.LastName, errStr = processFormField(r, &quot;lastname&quot;)<br>  errs = appendError(errs, errStr)<br>  user.Email, errStr = processFormField(r, &quot;email&quot;)<br>  errs = appendError(errs, errStr)<br>  user.City, errStr = processFormField(r, &quot;city&quot;)<br>  errs = appendError(errs, errStr)<br>  <br>  ageStr, errStr = processFormField(r, &quot;age&quot;)<br>  if len(errStr) != 0 {<br>    errs = append(errs, errStr)<br>  } else {<br>    user.Age, err = strconv.Atoi(ageStr)<br>    if err != nil {<br>      errs = append(errs, &quot;Parameter &#39;age&#39; not an integer&quot;)<br>    }<br>  }<br>  return user, errs<br>}</pre><h4>B. Reading users</h4><p>The Users/get.go script handles our two GET requests: Get() is called for fetching all users (http://localhost:8080/users), and GetOne() to fetch a single user with a resource ID (http://localhost:8080/users/UUID).</p><p>We start out by declaring our package name and our imports. Because we’ll be pulling data from Cassandra using the GoCQL library, we must make sure to include those. We also include the gorilla/mux library to access the UUID value from our GetOne() endpoint.</p><pre>package Users<br><br>import (<br>  &quot;net/http&quot;<br>  &quot;github.com/gocql/gocql&quot;<br>  &quot;encoding/json&quot;<br>  &quot;github.com/username/projectname/Cassandra&quot;<br>  &quot;github.com/gorilla/mux&quot;<br>  &quot;fmt&quot;<br>)</pre><p>To begin, we’ll outline our code to fetch all users. A best practice on this, of course, would restrict the number of results per call and to take in limit/offset parameters, but we will skip that in this tutorial.</p><p>Querying Cassandra data using GoCQL looks just like SQL you would write for MySQL or PostgreSQL. We pass the query as a string to our session’s Cassandra.Query() function. The Query() function returns an iterable, and we use the iterable’s MapScan() function to copy data into a map[string]interface (we use a map[string]<strong>interface</strong> because perhaps not all data in the table is string data to use map[string]<strong>string</strong>).</p><p><strong>Go #protip:</strong> When you’re dealing with alternate data types, you can use prefix-style casting like int(myVariable) similar to C, Python, etc.. However, when you have data in a Go interface, you must use a suffix-style casting, which looks like myVariable.(int)</p><p>We append each User structure to an array as we iterate through each user. One quirk of the GoCQL iterable is that we must empty the map before the next call to MapScan(), which is the last step in our for loop. Finally, we package up our array of User structures and return it as JSON. Here’s the code:</p><pre>func Get(w http.ResponseWriter, r *http.Request) {<br>  var userList []User<br>  m := map[string]interface{}{}<br><br>  query := &quot;SELECT id,age,firstname,lastname,city,email FROM users&quot;<br>  iterable := Cassandra.Session.Query(query).Iter()<br>  for iterable.MapScan(m) {<br>    userList = append(userList, User{<br>      ID: m[&quot;id&quot;].(gocql.UUID),<br>      Age: m[&quot;age&quot;].(int),<br>      FirstName: m[&quot;firstname&quot;].(string),<br>      LastName: m[&quot;lastname&quot;].(string),<br>      Email: m[&quot;email&quot;].(string),<br>      City: m[&quot;city&quot;].(string),<br>    })<br>    m = map[string]interface{}{}<br>  }<br><br>  json.NewEncoder(w).Encode(UsersResponse{Users: userList})<br>}</pre><p>Our endpoint code in our application’s /main.go main() function will look like this, and be placed next to our other routes:</p><pre>router.HandleFunc(&quot;/users&quot;, Users.Get)</pre><p>Next, our code to fetch a single user by their UUID. Let’s start by showing you the endpoint route that goes in our application’s /main.go main() function:</p><pre>router.HandleFunc(&quot;/users/{user_uuid}&quot;, Users.GetOne)</pre><p>You’ll notice that unlike our other routes, we have a string wrapped in curly braces called user_uuid. This string declares a variable route name through which we can extract the user’s UUID from the requested URL.</p><p>To begin, we extract all URL variables (declared in those curly braces) into a map called vars, and then access user_uuid from that map. Next, we validate that string by passing it to to GoCQL’s parser for Cassandra UUID values to determine if the value is in fact a UUID. If the validation passes, we fetch that user’s data from Cassandra similar to how we fetched all users in the code above. The difference in this call is the ? placeholder in our query for binding parameters to avoid injection attacks. When we call the Cassandra session’s Query() method, we not only pass the string of the query, but each parameter to pass into the query to fill each question mark. In this example we also show how you can tell Cassandra to have single-node consistency when fetching data; this is, of course, redundant since we’re only running on a single node. We then iterate over our result set (even though we set a limit of one row) and return the User structure or an error.</p><pre>func GetOne(w http.ResponseWriter, r *http.Request) {<br>  var user User<br>  var errs []string<br>  var found bool = false<br><br>  vars := mux.Vars(r)<br>  id := vars[&quot;user_uuid&quot;]<br><br>  uuid, err := gocql.ParseUUID(id)<br>  if err != nil {<br>    errs = append(errs, err.Error())<br>  } else {<br>    m := map[string]interface{}{}<br>    query := &quot;SELECT id,age,firstname,lastname,city,email FROM users WHERE id=? LIMIT 1&quot;<br>    iterable := Cassandra.Session.Query(query, uuid).Consistency(gocql.One).Iter()<br>    for iterable.MapScan(m) {<br>      found = true<br>      user = User{<br>        ID: m[&quot;id&quot;].(gocql.UUID),<br>        Age: m[&quot;age&quot;].(int),<br>        FirstName: m[&quot;firstname&quot;].(string),<br>        LastName: m[&quot;lastname&quot;].(string),<br>        Email: m[&quot;email&quot;].(string),<br>        City: m[&quot;city&quot;].(string),<br>      }<br>    }<br>    if !found {<br>      errs = append(errs, &quot;User not found&quot;)<br>    }<br>  }<br><br>  if found {<br>    json.NewEncoder(w).Encode(GetUserResponse{User: user})<br>  } else {<br>    json.NewEncoder(w).Encode(ErrorResponse{Errors: errs})<br>  }<br>}</pre><p>Finally in our Users/get.go code, we have a function to fetch a user’s first and last name to “enrich” some data. We will use this function in our Messages code shortly, and so we must declare the function with a capital E so it is visible to other subpackages in our project.</p><p>As a best practice, enrichment code would usually retrieve an entire User structure not just a few fields, but we’re taking an easy approach on this for our example application. The Enrich() function takes an array of UUID values, does a single database lookup, and creates a map of the UUID (as a string, this is important later) and the user’s concatenated first and last name. If an empty list of UUIDs is passed, an empty map is returned, otherwise it will return any results it finds in Cassandra.</p><pre>func Enrich(uuids []gocql.UUID) map[string]string {<br>  if len(uuids) &gt; 0 {<br>    names := map[string]string{}<br>    m := map[string]interface{}{}<br><br>    query := &quot;SELECT id,firstname,lastname FROM users WHERE id IN ?&quot;<br>    iterable := Cassandra.Session.Query(query, uuids).Iter()<br>    for iterable.MapScan(m) {<br>      fmt.Println(&quot;m&quot;, m)<br>      user_id := m[&quot;id&quot;].(gocql.UUID)<br>      names[user_id.String()] = fmt.Sprintf(&quot;%s %s&quot;, m[&quot;firstname&quot;].(string), m[&quot;lastname&quot;].(string))<br>      m = map[string]interface{}{}<br>    }<br>    return names<br>  }<br>  return map[string]string{}<br>}</pre><p>Full Source: <a href="https://github.com/GetStream/Stream-Example-Go-Cassandra-API/tree/master/Users">Users/*.go</a></p><h4>Step 6 — Connecting to Stream</h4><p>Great, we’ve learned how to set up the beginnings of our RESTful API with Go and Cassandra. As a next step let’s see how we can integrate Stream, our API for building scalable feeds and activity streams. We’ll use Stream to store a copy of our messages, so when our application goes viral it will be Stream’s job to handle the scalability of handling our activity feed.</p><p>Our Stream code will live in a separate subfolder as well, called “Stream” with its own main.go. Like the Cassandra code, it must have its own unique package name as well. We will import the Stream Go SDK library as well as the standard library for reporting errors. Inside Stream/main.go place the following code:</p><pre>package Stream<br><br>import (<br>  getstream &quot;github.com/GetStream/stream-go&quot;<br>  &quot;errors&quot;<br>)</pre><p>Next, we will declare an exportable variable called Client which we will use elsewhere in our code:</p><pre>var Client *getstream.Client</pre><p>Unlike our Cassandra code, this subpackage will not use the init() method so that the Connect() method will be called from our API application’s /main.go main() function. It will validate that we’ve passed in our API credentials and a region for the Stream SDK client and return an error if any of those items are missing. Next, the Stream SDK will create a new connection and assign that to our Client variable, or return an error if the connection failed.</p><pre>func Connect(apiKey string, apiSecret string, apiRegion string) error {<br>  var err error<br>  if apiKey == &quot;&quot; || apiSecret == &quot;&quot; || apiRegion == &quot;&quot; {<br>    return errors.New(&quot;Config not complete&quot;)<br>  }<br><br>  Client, err = getstream.New(&amp;getstream.Config{<br>    APIKey: apiKey,<br>    APISecret: apiSecret,<br>    Location: apiRegion,<br>  })<br>  return err<br>}</pre><p>Since we’re not using an init() call, we will require our application’s /main.go main() function to manually connect to Stream, and here’s what that code could look like:</p><pre>func main() {<br>  err := Stream.Connect(<br>    &quot;api_key_goes_here&quot;,<br>    &quot;api_secret_goes_here&quot;,<br>    &quot;us-east&quot;)<br>  if err != nil {<br>    log.Fatal(&quot;Could not connect to Stream, abort&quot;)<br>  }<br><br>  CassandraSession := Cassandra.Session<br>  defer CassandraSession.Close()<br><br>  router := mux.NewRouter().StrictSlash(true)<br>  ...<br>}</pre><p>Final source: <a href="https://github.com/GetStream/Stream-Example-Go-Cassandra-API/blob/master/Stream/main.go">Stream/main.go</a></p><h4>Step 8 — Messages</h4><p>We won’t go into the code for our messages as deeply as users because much of the structure is the same. Of course, all of our Messages scripts need to be declared with another unique package name:</p><pre>package Messages</pre><p>Our imports will also look the same, importing some standard libraries, gorilla/mux, and our Cassandra code. The GET and POST operations will also import our Stream submodules (not all scripts will need both):</p><pre>import (<br>  ...<br>  &quot;github.com/username/projectname/Stream&quot;<br>  getstream &quot;github.com/GetStream/stream-go&quot;<br>  ...<br>)</pre><p><strong>Go #protip:</strong> Adding a word in front of an import like the Stream Go SDK above (“getstream”) will allow you to alias the subpackage namespace. In our tutorial, our Stream code uses a package name of “Stream” which conflicts with the SDK package, so we can use “getstream” as an alias when we reference the SDK calls.</p><h4>A. Creating Messages</h4><p>Like our Users code, we have a Messages/structs.go script which declares our data structures. Our first structure holds the message details from Cassandra, plus one extra field for the user’s full name (more on this later). The next two structures are for requesting one or all messages.</p><p>The processing.go file is a much simpler version of the user’s processing script and handles incoming form data for the POST request to save a new message. It only declares whether a required field is missing in the form data.</p><p>Before we get into the code, let’s review at a high level what our Message/post.go script will do for us, because creating a new message becomes more complex than just creating a user. First, we must validate our data points and save it in Cassandra, but then we’ll also forward the activity to Stream as an activity on a flat feed called “messages” to retrieve later.</p><pre>package Messages<br><br>import (<br>  &quot;net/http&quot;<br>  &quot;github.com/gocql/gocql&quot;<br>  &quot;encoding/json&quot;<br>  &quot;github.com/username/projectname/Stream&quot;<br>  &quot;github.com/username/projectname/Cassandra&quot;<br>  getstream &quot;github.com/GetStream/stream-go&quot;<br>)</pre><p>Our message POST will require a user’s UUID to be part of our form data, as well as the text of the message itself. The validations below will check that the user_id passed to our code is a UUID, and that the message text has a length greater than 0. Of course, for simplicity, we skip validating that the user_id UUID is valid, and we also skip validating a maximum length on our message or perhaps other techniques to detect spam or unwanted behavior.</p><pre>func Post(w http.ResponseWriter, r *http.Request) {<br>  var errs []string<br>  var errStr, userIdStr, message string<br><br>  if userIdStr, errStr = processFormField(r, &quot;user_id&quot;); len(errStr) != 0 {<br>    errs = append(errs, errStr)<br>  }<br>  user_id, err := gocql.ParseUUID(userIdStr)<br>  if err != nil {<br>    errs = append(errs, &quot;Parameter &#39;user_id&#39; not a UUID&quot;)<br>  }<br><br>  if message, errStr = processFormField(r, &quot;message&quot;); len(errStr) != 0 {<br>    errs = append(errs, errStr)<br>  }</pre><p>Once our validation is proven, we generate a unique UUID for our message and insert the message into Cassandra similar to how we inserted our user record.</p><pre>gocqlUuid := gocql.TimeUUID()<br><br>  var created bool = false<br>  if len(errs) == 0 {<br>    if err := Cassandra.Session.Query(`<br>      INSERT INTO messages (id, user_id, message) VALUES (?, ?, ?)`,<br>      gocqlUuid, user_id, message).Exec(); err != nil {<br>      errs = append(errs, err.Error())<br>    } else {<br>      created = true<br>    }<br>  }</pre><p>If our message was created successfully in Cassandra, we can now build an Activity and send it to Stream. We start out by identifying our flat feed group called “messages” and passing an identifier as the word “global”; as mentioned earlier, we recommend passing a UUID value to avoid collisions, but this is common for global feeds of data that you want all users to see. We build the feed reference by calling our exported Client variable in our Stream subpackage, and calling the .FlatFeed() method.</p><pre>if created {<br>    // send message to Stream<br>    globalMessages, err := Stream.Client.FlatFeed(&quot;messages&quot;, &quot;global&quot;)</pre><p>With our feed in place, we now create an Activity structure and pass it to Stream. At the very minimum, the Stream API requires three pieces of data to build an activity: an Actor, a Verb, and an Object. The actor is usually set to the user who is creating the activity. The verb can be any string up to 20 characters in length, and we’ll set that to “post” for users posting a message. The object reference in this case is the UUID of the message we just saved in Cassandra.</p><p>The Stream API also allows metadata to be passed in activities, and the total payload of a message can be about 1kb of key/value pairs of string data. Normally, your application would use the Object ID described above to fetch the message structure, but on an application like this, the messages table could be quite large. So, to save us a database lookup later on our messages table, we will assume that messages sent to our API are short (say, Twitter-length in size), and store the text of the message in the activity metadata. This way, when we retrieve the feed from Stream later, we have less database activity.</p><pre>if err == nil {<br>      globalMessages.AddActivity(&amp;getstream.Activity{<br>        Actor: getstream.FeedID(user_id.String()),<br>        Verb: &quot;post&quot;,<br>        Object: getstream.FeedID(gocqlUuid.String()),<br>        MetaData: map[string]string{<br>          // add as many custom keys/values here as you like<br>          &quot;message&quot;: message,<br>        },<br>      })<br>    }<br><br>    json.NewEncoder(w).Encode(NewMessageResponse{ID: gocqlUuid})<br>  } else {<br>    json.NewEncoder(w).Encode(ErrorResponse{Errors: errs})<br>  }<br>}</pre><h4>B. Reading Messages</h4><p>Our Messages/get.go script will also be more complex than our Users code. Fetching a single message will pull it from the database but fetching all messages will first attempt to pull the messages from Stream; if Stream fails, we will look them up in the database.</p><pre>package Messages<br><br>import (<br>  &quot;net/http&quot;<br>  &quot;github.com/gocql/gocql&quot;<br>  &quot;encoding/json&quot;<br>  &quot;github.com/gorilla/mux&quot;<br>  &quot;fmt&quot;<br>  &quot;github.com/username/projectname/Stream&quot;<br>  &quot;github.com/username/projectname/Cassandra&quot;<br>  &quot;github.com/username/projectname/Users&quot;<br>)</pre><p>Our GetOne() method will be called only when our API is fetching a single message. It will use the gorilla/mux Vars() call again (like we did with users) to parse a value out of our URL string, in this case something called {message_uuid}. We validate that the value is indeed a UUID, and then fetch that from our database.</p><p>Our GetOne() and Get() calls will also “enrich” some data from the messages. This is typical behavior with applications using Stream since our Activity payload is relatively small. Most of the time, your application will only send us references to users, messages, posts, and other object types, which are then retrieved in an efficient manner from your database. In our example, we will take the user_id UUID from our message and turn that into a string of just the user’s first and last name; more typically, your application would pull the entire user record to access any of the fields.</p><p>We’ve included our Users subpackage in the imports above so we have access to the Enrich() code in the Users/get.go script. This method takes a list of user_id UUIDs and returns a map of firstname/lastname strings.</p><pre>func GetOne(w http.ResponseWriter, r *http.Request) {<br>  var message Message<br>  var errs []string<br>  var found bool = false<br><br>  vars := mux.Vars(r)<br>  id := vars[&quot;message_uuid&quot;]<br><br>  uuid, err := gocql.ParseUUID(id)<br>  if err != nil {<br>    errs = append(errs, err.Error())<br>  } else {<br>    m := map[string]interface{}{}<br>    query := &quot;SELECT id,user_id,message FROM messages WHERE id=? LIMIT 1&quot;<br>    iterable := Cassandra.Session.Query(query, uuid).Consistency(gocql.One).Iter()<br>    for iterable.MapScan(m) {<br>      found = true<br>      user_id := m[&quot;user_id&quot;].(gocql.UUID)<br>      names := Users.Enrich([]gocql.UUID{user_id})<br>      fmt.Println(&quot;names&quot;, names)<br>      message = Message{<br>        ID: user_id,<br>        UserID: m[&quot;user_id&quot;].(gocql.UUID),<br>        UserFullName: names[user_id.String()],<br>        Message: m[&quot;message&quot;].(string),<br>      }<br>    }<br>    if !found {<br>      errs = append(errs, &quot;Message not found&quot;)<br>    }<br>  }<br><br>  if found {<br>    json.NewEncoder(w).Encode(GetMessageResponse{Message: message})<br>  } else {<br>    json.NewEncoder(w).Encode(ErrorResponse{Errors: errs})<br>  }<br>}</pre><p>Finally, our Get() method will fetch all messages in our “messages” feed at Stream. If something goes wrong, we need a backup and so we’ll retrieve the messages from Cassandra. Either way, we’ll strip out all user_id UUIDs while we iterate over the data, fetch their firstname/lastname strings, and enrich the message data to include the author’s name in our outgoing payload.</p><pre>func Get(w http.ResponseWriter, r *http.Request) {<br>  var messageList []Message<br>  var enrichedMessages []Message<br>  var userList []gocql.UUID<br>  var err error<br>  m := map[string]interface{}{}</pre><p>Next, we create our reference to our flat feed as we did in Messages/post.go using our exported Client variable from our Stream subpackage.</p><pre>globalMessages, err := Stream.Client.FlatFeed(&quot;messages&quot;, &quot;global&quot;)</pre><p>Now we’ll attempt to fetch our flat feed from Stream by calling the .Activities() method on our feed reference, and print a message saying that we have successfully fetched the feed. Then we iterate over the list of activities, and extract all of the user_id UUIDs.</p><pre>// fetch from Stream<br>  if err == nil {<br>    activities, err := globalMessages.Activities(nil)<br>    if err == nil {<br>      fmt.Println(&quot;Fetching activities from Stream&quot;)<br>      for _, activity := range activities.Activities {<br>        fmt.Println(activity)<br>        user_id, _ := gocql.ParseUUID(activity.Actor.Value())<br>        message_id, _ := gocql.ParseUUID(activity.Object.Value())<br>        messageList = append(messageList, Message{<br>          ID: message_id,<br>          UserID: user_id,<br>          Message: activity.MetaData[&quot;message&quot;],<br>        })<br>        userList = append(userList, user_id)<br>      }<br>    }<br>  }</pre><p>However, this is the internet we’re talking about and sometimes things fail. We could build in a retry mechanism with exponential back-off, but our users want to see messages as soon as possible, so let’s fetch them from Cassandra as our backup plan. While we iterate over those messages, we’ll also pull out the user_id UUIDs into a list.</p><pre>// if Stream fails, pull from database instead<br>  if err != nil {<br>    fmt.Println(&quot;Fetching activities from Database&quot;)<br>    query := &quot;SELECT id,user_id,message FROM messages&quot;<br>    iterable := Cassandra.Session.Query(query).Iter()<br>    for iterable.MapScan(m) {<br>      user_id := m[&quot;user_id&quot;].(gocql.UUID)<br>      messageList = append(messageList, Message{<br>        ID: m[&quot;id&quot;].(gocql.UUID),<br>        UserID: user_id,<br>        Message: m[&quot;message&quot;].(string),<br>      })<br>      userList = append(userList, user_id)<br>      m = map[string]interface{}{}<br>    }<br>  }</pre><p>Now we’ll take that list of user_id UUIDs from above, turn that into our map of UUID-&gt;”firstname lastname” and enrich our messages. Since we cannot inject data into our old messages list, we append the now-enriched messages into a new list, and return that as our payload.</p><pre>names := Users.Enrich(userList)<br>  for _, message := range messageList {<br>    message.UserFullName = names[message.UserID.String()]<br>    enrichedMessages = append(enrichedMessages, message)<br>  }<br><br>  json.NewEncoder(w).Encode(MessagesResponse{Messages: enrichedMessages})<br>}</pre><p>Final Source: <a href="https://github.com/GetStream/Stream-Example-Go-Cassandra-API/tree/master/Messages">Messages/*.go</a></p><h4>Conclusion</h4><p>Building a performant API isn’t hard when you’ve learned the REST principles of keeping your data payloads simple, with one responsibility, and having appropriate JSON responses for payloads. Our example API application showed you how to create a simple API in Go built on gorilla/mux and using Cassandra as a datastore. We also showed an example of using the <a href="https://github.com/GetStream/stream-go">Stream Go SDK</a> to save and retrieve message data with Stream’s flat feeds.</p><p>If you’d like to see more of our open-source projects, you can find them at <a href="https://github.com/GetStream">github.com/GetStream</a> and you can go through our <a href="https://getstream.io/get_started/?utm_source=blog&amp;utm_campaign=growth&amp;utm_medium=go-api#intro">Getting Started tutorial</a> to learn more about our flat feeds and other feed types!</p><p><em>Originally published at </em><a href="http://blog.getstream.io/building-a-performant-api-using-go-and-cassandra/"><em>The Stream Blog</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7b11b7d58" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>