<?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 Cuppatea on Medium]]></title>
        <description><![CDATA[Stories by Cuppatea on Medium]]></description>
        <link>https://medium.com/@alexsoong?source=rss-425aeb75591b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*w-TgMkriDu8dOYd-4QCKPw.jpeg</url>
            <title>Stories by Cuppatea on Medium</title>
            <link>https://medium.com/@alexsoong?source=rss-425aeb75591b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 10:08:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alexsoong/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[What Version of Your Code is Running, and Where ?]]></title>
            <link>https://blog.devgenius.io/what-version-of-your-code-is-running-and-where-b200ec7353bc?source=rss-425aeb75591b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b200ec7353bc</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Cuppatea]]></dc:creator>
            <pubDate>Sun, 16 Jan 2022 19:40:06 GMT</pubDate>
            <atom:updated>2022-01-16T20:58:10.638Z</atom:updated>
            <content:encoded><![CDATA[<h3>What Version of Your Code is Running, and Where ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*cF3i5ONniuSob6cH.png" /><figcaption>Image from github.com</figcaption></figure><h3>Background</h3><p>It’s quite common for software engineering teams to have multiple deployment environments as part of their development and CICD pipelines. Multiple deployment environments allows you to release and test features thoroughly without disrupting the what end users and external systems see. Having this well developed and seamless workflow allows teams to be more productive and ship reliable software in a timely manner.</p><p>A common pattern of these environments is:</p><ul><li><strong>Development (or just dev): </strong>Many times this environment may be a developer’s local environment, or a virtual machine in the cloud with minimal supporting infrastructure. This environment is usually considered the first line of defense of bugs, where the developer is testing out new features with a suite of unit tests to ensure their code logic is sound and all corner cases are covered. This cycle of <em>develop, unit test, develop, unit test</em> is performed until the developer merges their code and pushes to the next environment for further testing.</li><li><strong>Staging: </strong>The staging environment is where QA and integration tests usually take place. Depending on the application, either a person or an automated framework will confirm that the newly developed software behaves as expected and does not break any upstream or downstream services. If bugs are found, they are reported back to the developer and the cycle begins again of <em>develop, unit test, …</em> continues.</li><li><strong>Production: </strong>Once all parties (dev team, QA team, ..) agree that the code has been thoroughly tested the code is sent to the production environment, and happily ever after.</li></ul><h3>What Brought Me Here</h3><p>Except that it’s never that simple. Bugs are found in staging/production, outages happen, a service may deprecate an endpoint, and it will be the developer’s and his or her team’s responsibility to track down the source of the issue and <strong><em>debug.</em></strong></p><p>How can we make this easier? There are any where from 1 to <em>n </em>developers committing code to your repository every day, pushing changes and shipping deployments to all your environments. How can we track down what code was executed where?</p><p>I ran into this issue when I was building out my docker-compose and AWS Elastic Beanstalk environment over the last month or so. I had succeeded in deploying and running the application, connecting to RDS, queued up celery tasks and so on and so forth, but lo and behold there was a bug. My application crashed.</p><p>I did some digging around of ways I could figure out from my application logs, which version of the code I was running. Sure, I had New Relic up and running already, and it was giving me stack traces, but no where did it say what version of my code was running. And this became a story of how I tried to figure out how to get the latest git commit hash as a parameter into my Docker container.</p><h3><strong>Injecting the Latest Git Commit Hash into Docker</strong></h3><p>There were two places where I felt I needed to, and <em>could</em> get the git hash from. I’ll briefly highlight both of the methods below.</p><h4><strong>Dockerfile:</strong></h4><p>I figured I could directly add my git commit hash as an Argument into the Dockerfile as an ARG . From that point you would be able to set it as an environment variable and have it be used throughout your code for any number of use cases; for me, this became setting it in the extra={}parameter in the logging... functions. Your docker build command would look something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/596c7df039d5387924d16a723b0e0e99/href">https://medium.com/media/596c7df039d5387924d16a723b0e0e99/href</a></iframe><p>Build arguments from the command line, or not, can be accessed from within the Dockerfile. I use it to set an environment variable within my application so I know which secrets to pull from <a href="https://aws.amazon.com/secrets-manager/">Amazon Secrets Manager.</a> However for this specific use case, I am just going to use it as an environment flag to denote the current git commit hash of the code that I’m building and pushing. Now that I have the variable in my python environment, I can use it however I like. Check our more ways to use Dockerfile ARGs <a href="https://docs.docker.com/engine/reference/builder/#arg">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74f5cfa6b9b11d4edde4897c3f593bb3/href">https://medium.com/media/74f5cfa6b9b11d4edde4897c3f593bb3/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac73eaf454276e6ae57a836dffb91094/href">https://medium.com/media/ac73eaf454276e6ae57a836dffb91094/href</a></iframe><h4><strong>Github Actions:</strong></h4><p>At some point, I will write about how <a href="https://docs.github.com/en/actions">Github Actions</a>, and some of the favorites that I plug into our CICD pipeline. That includes one of the custom jobs I wrote to deploy to my <a href="https://awstip.com/taking-a-fastapi-app-to-production-on-aws-189ebf3defed">Elastic Beanstalk environment</a>!</p><p>We can achieve what we did from the command line above with an extra step in your Github Action for building your Docker image. First, we need to understand how to use environment variables in Github Actions. The gist of it is, Github sets default arguments for your workflow runs, <em>and</em> you can also add custom variables in your code! A list of default environment variables provided by Github can be found <a href="https://docs.github.com/en/actions/learn-github-actions/environment-variables">here</a>, these variables can be accessed in your workflow by adding a $ before the variable name. For example, to print GITHUB_SHA my command could look like this within the action’s step:</p><pre>name: Print Git Hash<br>    shell: bash<br>    run: |<br>        echo $GITHUB_SHA</pre><p>For the sake of learning, let&#39;s set this default environment variable as a custom one, and use it in our build step of the workflow. I think the most straightforward way of adding a custom variable as an environment variable is echo-ing the variable into the $GITHUB_ENV. After doing so, you can use the variable by calling env.&lt;var_name&gt;</p><pre>name: Extract Git Hash<br>    shell: bash<br>    run: |<br>        echo &quot;sha=$GITHUB_SHA&quot; &gt;&gt; $GITHUB_ENV</pre><pre>name: Print Git Hash<br>    shell: bash<br>    run: |<br>        echo ${{ env.sha }}</pre><p>Finally, you can set your custom variable as a build-arg to the docker/build-push-action@v2 step. Re-iterating my point from before, doing it through a GitHub action like this is essentially the same as using the command line option from before, it’s just automated now. A complete picture of setting the commit hash and using it as a build arg in your workflow could look something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e48ed66f0bd7ca8278f149eb79d7bc50/href">https://medium.com/media/e48ed66f0bd7ca8278f149eb79d7bc50/href</a></iframe><h3><strong>What Does This Do For Me?</strong></h3><p>Referencing my <a href="https://awstip.com/logging-and-monitoring-elastic-beanstalk-with-new-relic-eb6ad00e7db9">previous article</a> on how my application does logging to New Relic, I mentioned that the goal was to take our application logs from different environments to a query-able interface for debugging purposes. The logging with context enabled me to see which infrastructure logs were tied to which APM, and now this takes the observability to another level. Any discrepancies between which versions of code are running can be denoted by my new environment variable!</p><p>The different <a href="https://awstip.com/logging-and-monitoring-elastic-beanstalk-with-new-relic-eb6ad00e7db9">log level functions</a> all can have a extra kwarg that passes in a dictionary of values to fill out your logger’s format string. The newrelic.agent.NewRelicContextFormattertakes whatever I pass into the extra dictionary and adds it to the LogRecord!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_naO2OMVxGFOUje0giuJig.jpeg" /><figcaption>Example of a log from New Relic with the GIT_HASH variable!</figcaption></figure><p>Happy debugging!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b200ec7353bc" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/what-version-of-your-code-is-running-and-where-b200ec7353bc">What Version of Your Code is Running, and Where ?</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging and Monitoring Elastic Beanstalk with New Relic]]></title>
            <link>https://awstip.com/logging-and-monitoring-elastic-beanstalk-with-new-relic-eb6ad00e7db9?source=rss-425aeb75591b------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb6ad00e7db9</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[logging-and-monitoring]]></category>
            <category><![CDATA[new-relic]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[elastic-beanstalk]]></category>
            <dc:creator><![CDATA[Cuppatea]]></dc:creator>
            <pubDate>Sun, 09 Jan 2022 05:58:55 GMT</pubDate>
            <atom:updated>2022-01-18T18:17:16.676Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*JgQgdzJw89UE6_na" /><figcaption>Image from New Relic</figcaption></figure><h3>Background</h3><p>In my last <a href="https://awstip.com/taking-a-fastapi-app-to-production-on-aws-189ebf3defed">article</a>, I talked about how I took my FastAPI application from a proof of concept to a production ready state in AWS. Some of the technologies I used were docker-compose deployed on Beanstalk, and Celery Workers running on an Elasticache instance. If you have not had a chance to read that over, check it out <a href="https://awstip.com/taking-a-fastapi-app-to-production-on-aws-189ebf3defed">here</a>!</p><h3>Logging</h3><p>In my docker-compose application, I had two major moving pieces. A container for the FastAPI app, and another container for the Celery Worker. By default these frameworks can log their system logs to stderr.out when you open an interactive shell, or to a file because they all take advantage of the python logging module. For my specific deployment in Elastic Beanstalk I opted to write the logs out to a file using the logging.FileHandler in order to persist the logs in some way. (I wouldn’t be able to retrieve previous logs if they were just written out to the console).</p><p>Beyond persisting logs, I wanted the ability to parse, query and search for logs matching certain criteria, whether that might be a particular service, a keyword, Git hash or docker container. <a href="https://docs.newrelic.com/docs/logs/get-started/get-started-log-management/">New Relic Logging</a> offers us this functionality to make use of our logs when debugging production errors or testing new features. For this implementation of writing logs to a volume and forwarding to New Relic there are three major steps involved:</p><p><strong>Configuring Your Loggers Properly</strong></p><p>When you start your celery application, by default it set’s up its logger. After this initial logger configuration is completed, it sends this signal: after_logger_setup.connect. This celery signal passes in the logger: logging.getLogger(__name__) to a setup_loggers() where you can setup handlers and formatters. I used a simple logging.FileHandler to write my logs out to directory. In order to have New Relic be able to interpret your logs and populate attributes properly you need to use the newrelic.agent.NewRelicContextFormatter to format the logs. My celery setup_loggers() function looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e6346b8a73bd61dd150ebc3d40be5de/href">https://medium.com/media/6e6346b8a73bd61dd150ebc3d40be5de/href</a></iframe><p>For your FastAPI web server, you can configure your logger as if you were configuring any other FileHandler. The only real difference is using the NewRelicContextFormatter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4284eed82ba7c3cba48c15e6e6a53f1f/href">https://medium.com/media/4284eed82ba7c3cba48c15e6e6a53f1f/href</a></iframe><p>With these configurations you’ll have your logs from both the web server and Celery Worker logging to the defined log directory. You might be thinking, what log directory is this? Does it matter where I log to? <em>Yes it does!</em></p><p><strong>Extracting Docker Compose Logs in Beanstalk</strong></p><p>The Elastic Beanstalk environment will, by default, automatically create n number of directories for your n containers defined in the deployment artifacts docker-compose.yml file. These created directories exist in the parent directory denoted by the variable which is made available to your docker compose environment. EB_LOG_BASE_DIR=/var/log/eb-docker/containers. These directories should match the directories you defined in your loggers as the destination of your application logs! Every time a log is appended to those directories in your docker containers, the change will be effected into the mounted volume in the Beanstalk environment.</p><p>Making this addition to my docker-compose.yml described in my previous <a href="https://awstip.com/taking-a-fastapi-app-to-production-on-aws-189ebf3defed">article</a> would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13e3f856a4ccfb661dc599a89fc59aba/href">https://medium.com/media/13e3f856a4ccfb661dc599a89fc59aba/href</a></iframe><p><strong>Forwarding Logs to New Relic</strong></p><p>The final piece is taking the logs Elastic Beanstalk has collected in the mounted directories and sending them to New Relic via the newrelic-infra agent. This agent is installed by following the instructions in /.ebextensions/newrelic.config file that is in your deployment artifact. The config has steps for downloading the agent to the Linux environment, updating yum (or whichever package manager for your Linux flavor) and installing the agent.</p><p>In addition to installing the infrastructure agent, it will also plant a few files that tell the agent where to collect logs from to forward to New Relic. Again, the file path you provide to the logging.d/logging.yml configuration file should match the pattern:EB_LOG_BASE_DIR/log-directory/your_log_file.log If your writing multiple log files from your application you can pass a *.log as well. A full description for the infra agent installation can be found <a href="https://docs.newrelic.com/docs/infrastructure/install-infrastructure-agent/get-started/install-infrastructure-agent/">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f74a53245bac94abc288164465f2be79/href">https://medium.com/media/f74a53245bac94abc288164465f2be79/href</a></iframe><h3>Monitoring</h3><p>In addition to reading and interpreting application logs, I wanted a way to monitor my application’s performance. The ability to analyze throughput and response all the way down to the granularity of inspecting individual web and database transactions is critical when scaling up applications. <a href="https://docs.newrelic.com/docs/apm/new-relic-apm/getting-started/introduction-apm/">New Relic APM</a> provides us with basic out of the box metrics like throughput, web transaction time and error rate. To achieve APM monitoring, there were also three major steps I had to follow:</p><p><strong>Setting Up the APMs</strong></p><p>In order for our FastAPI to send these metrics to New Relic, we needed to pip install their newrelic-admin agent in our python environment, and register our application as an APM. For this all to happen our Elastic Beanstalk environment uses three different environment variables:</p><pre>NEW_RELIC_LICENSE_KEY: string tied to your account<br>NEW_RELIC_ENVIRONMENT: string mapping to APM definition in .ini file NEW_RELIC_CONFIG_FILE: path to .ini file containing APM configs</pre><p>Within your newrelic.ini file, there are certain configurations for how you want to run your APM application that will be tied to your account via the license key you were assigned at account creation. Some of these configurations include error_collection and distributed_tracing . The new-relic admin agent looks for the NEW_RELIC_ENVIRONMENT variable to map to an APM definition, which has an application name and a boolean flag to mark whether or not this application should be monitored. A typical APM definition looks something like this:</p><pre># Template</pre><pre>[newrelic:&lt;NEW_RELIC_ENVIRONMENT&gt;]<br>app_name = &lt;Whatever name you want on New Relic UI&gt;<br>monitor_mode = &lt;boolean to monitor or not (true/false)&gt;</pre><p><strong>Tweaking Environment Variables to Support Multiple Deployments</strong></p><p>You can take advantage of having multiple different values of NEW_RELIC_ENVIRONMENT in your different environments, and just add an APM definition to your newrelic.ini file to create multiple APM applications. A common use case for this is having separate dev, staging and production environments e.g. (dev-webserver, prod-webserver)</p><p>Another spin you can take on this is, if you want to separate your celery worker logs from the web server logs. You can do a combination of mixing celery/web server and different environment flags to come up with separate APM environments. For our infrastructure, we have a total of 4 APMs: a web server and a celery worker APM for both a staging and a prod environment.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c88e2d5cf869aab70e56f913c3a6ce6/href">https://medium.com/media/6c88e2d5cf869aab70e56f913c3a6ce6/href</a></iframe><p><strong>Running the Python Application as a Registered APM App</strong></p><p>Lastly, what you need to do is change how you start your application whether it be django, FastAPI, Celery for Flask. Good thing is that it is actually quite easy to do this. You insert a newrelic-admin run-program at the front of your start command for your application:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4872334809aae74d4278ef5067f75fa3/href">https://medium.com/media/4872334809aae74d4278ef5067f75fa3/href</a></iframe><p>Now with your NEW_RELIC_ENVIRONMENT configured with your newrelic.ini file and your servers starting the right way, you should see APM metrics showing up in your New Relic account’s dashboard within 15 minutes.</p><h3>Logging With Context</h3><p>The end result of having your APM’s sending performance data to New Relic, and the Infrastructure Agent forwarding properly formatted logs is <a href="https://docs.newrelic.com/docs/logs/logs-context/configure-logs-context-apm-agents/">logging with context</a>. What this means is, you can link your log data to your APM data. For example: when you see a slowdown in transaction time, you can zoom in on the timeframe and look for logs signaling an error. Another feature this enables is distributed tracing, which enables you to follow logs throughout your micro-service architecture instead of hitting a wall when the line of execution ends for one service but starts for another.</p><p>Now I can fully inspect my production environments for application logic and performance! Theres still so much to share for this productionization project. Some of these include CICD with our github actions, and further customization of our application logs to provide environment specific information to the user. Stay tuned..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb6ad00e7db9" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/logging-and-monitoring-elastic-beanstalk-with-new-relic-eb6ad00e7db9">Logging and Monitoring Elastic Beanstalk with New Relic</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Taking a FastAPI App to Production on AWS]]></title>
            <link>https://awstip.com/taking-a-fastapi-app-to-production-on-aws-189ebf3defed?source=rss-425aeb75591b------2</link>
            <guid isPermaLink="false">https://medium.com/p/189ebf3defed</guid>
            <category><![CDATA[elastic-beanstalk]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Cuppatea]]></dc:creator>
            <pubDate>Tue, 28 Dec 2021 17:35:34 GMT</pubDate>
            <atom:updated>2022-01-18T18:18:41.497Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*RLs82TdVnTn3RoWH.jpg" /><figcaption>Image from AWS</figcaption></figure><h4>Where we started</h4><p>Once upon a time when I first joined Komodo Health, my team’s application was just gunicorn running a FastAPI application on a EC2 instance…</p><p>There was no scaling, monitoring, logging, or any supporting infrastructure in the cloud at that point. Just a standalone web server like a developers side project they developed over spring break. We were building a prototype of an application that would act as a API gateway to query all the data in the data warehouse for the other internal services and products to use. Performance and scalability became a top priority as we tried to integrate more and more teams onto our platform. My first major task was to try to help bring this application to a more production ready state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*adP3tcghqiY2W_R5XXY-ig.png" /><figcaption>Basic CRUD Application</figcaption></figure><h4><strong>Scaling up with Celery</strong></h4><p>Our application started out as a basic <a href="https://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> (Create, Replace, Update, Delete) application. We offered users a way to process query configurations to produce a count of the data points for a particular query in the API response, or write the data out to other outputs destination like Snowflake or AWS S3.</p><p>As the number of integrations and ideas for uses cases grew in volume and complexity, the bottleneck because our synchronous web server. There is only so much horizontal scaling you can do to keep web request latency low while keeping cost in mind.</p><p>We evolved our application to adopt an asynchronous task processing framework: <a href="https://docs.celeryproject.org/en/stable/index.html">Celery</a>, it is a distributed task queue with a <em>“focus on real-time processing, while also supporting task scheduling”. </em>We incorporated Celery into our application to keep the web server focused on handling requests, while off-loading some of the data-crunching tasks to designated Celery Workers.</p><p>With this implementation, the web server would:</p><ul><li>Receive a configuration of a query to run.</li><li>Log the creation of the the configuration in the database.</li><li>Kick off a Celery Task with the query to run.</li><li>If success: return a status code and configuration ID.</li><li>If failure: return a status code and error.</li><li>Handle next request</li></ul><p>and the Celery Worker would:</p><ul><li>Listen for events from a particular queue.</li><li>Receive a task with the query to run.</li><li>Execute the query, and log results to the database.</li><li>Wait for new events from the queue.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*R0_hplZ6nLu7POJpFfjE6A.png" /><figcaption>Incorporating Celery Workers and a queue into our application</figcaption></figure><h4>Docker and Elastic Beanstalk</h4><p>At this point, we wanted to scale up our deployment to handle more and more incoming traffic. At the same time wanted a solution that was quick and easy to implement and maintain. Instead of setting up a new Kubernetes cluster we took our application, threw the two pieces into a docker-compose, and deployed to Elastic Beanstalk.</p><p>Our docker setup has 2 containers, one for the FastAPI web server and one for the celery worker. The same docker image was reused; the difference between the two containers is the command when executing the container. For the web server, the command looked like a pretty generic <a href="https://docs.gunicorn.org/en/stable/run.html">gunicorn</a> run command:</p><pre>CMD gunicorn \</pre><pre>--bind 0.0.0.0:3000 \</pre><pre>--workers 5 \</pre><pre>--worker-class uvicorn.workers.UvicornWorker \</pre><pre>asgi:app</pre><p>Our Celery Worker takes the same code base, but instead of running the gunicorn asgi:app , we tell Celery where the application code is and run the worker. We put the run celery command in a shell script and copy the script into the working directory of the Docker application.</p><pre># start_celery.sh</pre><pre>celery -A my_module.my_folder.tasks worker --loglevel=INFO</pre><p>A simplified version of the resulting docker-compose file looked like this:</p><pre>version: &quot;3.9&quot;</pre><pre>services:</pre><pre>    app-webserver:</pre><pre>        image: my_image</pre><pre>        ports:</pre><pre>            - &quot;80:3000&quot; # i running gunicorn on port 3000</pre><pre>        env_file:</pre><pre>            - .env</pre><pre>    app-worker:</pre><pre>        image: my_image</pre><pre>        command: /start_celery.sh</pre><pre>        restart: always</pre><pre>        env_file:</pre><pre>            - .env</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*bwyS_jNjhKhMIvLy0WQTmA.png" /><figcaption>Dockerized application with a web server and celery worker</figcaption></figure><h4>Construct and Deploy the Build Artifact</h4><p><a href="https://aws.amazon.com/elasticbeanstalk/">Elastic Beanstalk</a> was a good choice for us because of the variety of deployment environments they offer. The built in load-balancing, auto-scaling, logging and provisioning of the required supporting infrastructure made the whole process easy as pie.</p><p>The Docker Platform on Elastic Beanstalk allows us to take applications with multiple containers defined in a docker-compose.yml and deploy to the environment. Once you have the environment configured properly the only things you need for this deployment are:</p><ul><li>docker-compose.yml</li><li>Dockerrun.aws.json</li><li>.elasticbeanstalk</li><li>.ebextensions</li></ul><p>If your docker-compose application involves using Docker images from a private Dockerhub you will need to provide your credentials to Elastic Beanstalk. Your Dockerhub credentials would be stored in a S3 bucket and defined in the Authentication portion of the Dockerrun.aws.json file.</p><pre># Example of my Dockerrun.aws.json file </pre><pre>{</pre><pre>    &quot;AWSEBDockerrunVersion&quot;: &quot;3&quot;,</pre><pre>    &quot;Authentication&quot;: {</pre><pre>        &quot;bucket&quot;: &quot;my-s3-bucket-with-docker-credentials&quot;,</pre><pre>        &quot;key&quot;: &quot;config/.dockercfg&quot;</pre><pre>    }</pre><pre>}</pre><p>The .elasticbeanstalk directory only requires one configuration file: config.yml . The contents include some basic configurations like which EB platform you’re using, which git branches are deployed to which environments but most importantly: the name of the deploy artifact if you are using the <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3.html">EB CLI</a>.</p><pre># Example of my config.yml within .elasticbeanstalk</pre><pre>deploy:</pre><pre>    artifact: eb_application.zip</pre><pre>environment-defaults:</pre><pre>    my-webserver:</pre><pre>        branch: null</pre><pre>        repository: null</pre><pre>global:</pre><pre>    application_name: my-webserver</pre><pre>    default_ec2_keyname: my-production-webserver</pre><pre>    default_platform: Docker running on 64bit Amazon Linux 2</pre><pre>    default_region: my-region-1</pre><pre>    include_git_submodules: true</pre><pre>    instance_profile: null</pre><pre>    platform_name: null</pre><pre>    platform_version: null</pre><pre>    profile: null</pre><pre>    sc: git</pre><pre>    workspace_type: Application</pre><p>Finally, the .ebextensions directory will contain any extra 3rd party applications you wish your EB environment to be running. You might notice so far I have not mentioned any logging or monitoring of our web application. <a href="https://newrelic.com/lp/apm?utm_campaign=Brand-Beta-NORAM&amp;utm_medium=cpc&amp;utm_source=google&amp;utm_content=APM_LP&amp;fiscal_year=FY21&amp;quarter=Q4&amp;gtm=DEV&amp;program=P2P&amp;ad_type=TXT&amp;geo=AMER&amp;utm_term=%2Bnew%20%2Brelic%20%2Bapm&amp;utm_device=c&amp;_bt=505336300202&amp;_bm=b&amp;_bn=g&amp;gclid=EAIaIQobChMI-v7Fw4GH9QIVBsqUCR2nwgD3EAAYASAAEgJWPPD_BwE">New Relic</a> was our APM and Logging solution of choice. This portion of the productionization project took quite a bit of setup and configuration so I will talk about it in a future post.</p><p>Together with all your components, you can create a zip file with a simple:</p><pre>zip -r docker-compose.yml Dockerrun.aws.json .elasticbeanstalk .ebextenstions</pre><p>and use either the CLI tool or the AWS UI to deploy your application to the cloud!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*2oqc4SV8pcce2AGIx3fpwQ.png" /><figcaption>Our final deployment to AWS — for now…</figcaption></figure><p>This sums up how I took my Fast API application to production in an AWS Elastic Beanstalk environment. Now any engineer on our team can simply build a new Docker image and deploy to our production environment. Some things I have not mentioned are a seamless deployment strategy with github actions, database scaling and logging/monitoring which I will mention in a future posts!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=189ebf3defed" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/taking-a-fastapi-app-to-production-on-aws-189ebf3defed">Taking a FastAPI App to Production on AWS</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Joined Komodo Health as a Software Engineer]]></title>
            <link>https://alexsoong.medium.com/i-joined-komodo-health-as-a-software-engineer-1c9a74f90d27?source=rss-425aeb75591b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c9a74f90d27</guid>
            <category><![CDATA[komodo-health]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Cuppatea]]></dc:creator>
            <pubDate>Fri, 17 Dec 2021 19:37:39 GMT</pubDate>
            <atom:updated>2021-12-19T18:29:03.523Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/284/0*ea9cd0kkMIbsYbOf" /></figure><h3><strong>Background</strong></h3><p>I first heard of Komodo Health two years ago when my friend joined as a data scientist. He mentioned to me all the cool things Komodo Health is doing with healthcare data, analyzing data from millions of patients across the entire US.</p><p>I reached out to a recruiter back in 2019 and applied for a data engineering role. I got to the middle of the interview process, but things didn’t progress further.</p><p>I gained some backend development experience over the past few years in addition to the data engineering work I was doing, so it made sense in my mind to consider software roles the next time I was on the job market. Coincidentally my recruiter at Komodo Health who gave me the first opportunity remembered my profile and approached me for a backend engineering role!</p><p>I made it all the way through this time and am working as backend services engineer on the Platform Team at Komodo Health. I thought I would share some of my experience so far.</p><h3><strong>Interview Process</strong></h3><h4><strong>HR screening interview</strong></h4><p>Setting up the first recruiter call was fast and simple. He let me know about the new round of funding that happened in early 2021, and the engineering headcount that was made available across different teams and functions. Within 2 days of him reaching out we had scheduled and conducted the HR screening interview.</p><p>During the HR screening interview, he asked me about the projects I worked on over the last two years, highlighting any backend and/or data engineering experiences. I mentioned working on the snowflake data warehouse, asynchronous task processing, and general Restful API development.</p><p>Afterwards, we discussed the alignment of my technical skills with the tech stack of Komodo Health. The tech stack at Komodo is heavily based around: snowflake, airflow and different python web frameworks like FastAPI and Flask. It seemed like a great fit.</p><h4><strong>First technical round: system design</strong></h4><p>A little out of the ordinary, but my first round was a system design instead of a coding exercise. The team I interviewed for, the team I’m currently on, is building out a universal api layer for our other internal products to access the data warehouse.</p><p>The long run vision of our system is that analysis can be executed through a manual trigger, upstream service call or timed orchestration; and ultimately this is what the system design problem was. Starting off with a very vague question we slowly builded on and interested through multiple ideas including but not limited to CRON jobs on Kubernetes, queue prioritization on rabbitMQ and using Airflow for more complicated task graphs.</p><p>My solution involved Celery Workers and RabbitMQ because this is where my experience stemmed from. To keep the web server relatively light weight I suggested that all the server was responsible for was parsing input and sending off a task to the queue. The workers would pick up the tasks in the queue specific to an external service and run the analytics job it tasked with. For timed and more orchestrated task flows, Airflow DAGs could trigger an API request to this web server and initiate a similar task to queue to output flow.</p><h4>Panel round: SQL, Python, Behavioral</h4><p><strong>SQL Interview</strong></p><p>The SQL interview went as expected: increasing level of difficulty involving different joins and testing overall knowledge of how a sql query is constructed and how sql clauses are ordered: select, from, where, group by, etc etc. I was asked a total of 4 sql questions over a 45 minute interview conducted on coderpad.io</p><p>The interview did go beyond my past sql interview in terms of difficulty coming from a backend engineering background. The third interview question involved a couple of window functions involving the basic aggregations: sum(), mean() and finally rank(). With a couple of iterations I was able to solve it</p><p>The last sql question was the trickiest. Given a table of:</p><blockquote>patient_id | condition_id | drug_id | record_date</blockquote><p>return all patient_id where a patient was administered a particular drug +/- 5 days to their diagnoses of a specific condition_id. Without going too much into detail, the solution involved a DATEDIFF and a self join. 😆</p><p><strong>Python Interview</strong></p><p>The python interview was probably the easiest for me to interpret and understand. I had 1 python problem to solve over a 45 minute interview conducted on coderpad.io</p><p>Given a list of stock candle stick data by the minute organized as a dict of metrics like (opening_price, closing_price, high, low, etc etc) , implement a function that consolidates the data to a list of candle stick data for every “n” minutes.</p><p>My solution involved a for loop that chunked iterations by the input “n”. On each iteration I performed simple arithmetic and manipulation of the data in the dictionaries like find the high of highs, low of lows, and mean of means.</p><p>With 30 minutes or so left of the interview, I got plenty of time to ask the engineer about the company, culture, projects and where the company is headed in general.</p><p><strong>Behavioral Interview</strong></p><p>My behavioral interview happened with a data product manager. Although I’ve heard this round of interviews happened with different people like a data scientist or tech lead.</p><p>All this round really was about was finding potential candidates that are passionate about the company mission statement: <strong><em>Reducing the burden of disease.</em></strong></p><h3>Results</h3><p>My recruiter got back to me within a day actually. It was a quick and pain free process (they really are in hyper growth). They let me know the feedback from the 4 people I got the chance to talk to, let me know about the compensation package and leveling and ultimately that I got the offer!</p><p>It’s been a roller coaster ever since working on interesting things on the platform team at Komodo Health. So many new technologies and frameworks that I had not previously used; however, the part that sticks with me most is how curious and intelligent everyone here is!</p><p>More to come on what I’ve learned ~~</p><p>PS</p><p>If you’re interested in joining Komodo Health, feel free to reach out to me for a referral at <a href="http://www.linkedin.com/in/alexsoong">www.linkedin.com/in/alexsoong</a></p><p><a href="https://www.komodohealth.com/careers/current-job-openings">Careers at Komodo Health</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c9a74f90d27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Who am I?]]></title>
            <link>https://alexsoong.medium.com/who-am-i-68817dda1705?source=rss-425aeb75591b------2</link>
            <guid isPermaLink="false">https://medium.com/p/68817dda1705</guid>
            <dc:creator><![CDATA[Cuppatea]]></dc:creator>
            <pubDate>Sat, 20 Nov 2021 19:27:14 GMT</pubDate>
            <atom:updated>2021-11-20T19:28:15.117Z</atom:updated>
            <content:encoded><![CDATA[<h3>The start</h3><p>My name is Alex and I grew up in Cupertino, California. I spent my entire childhood in CA and ended up going to college at UC Davis as well. It wasn’t until after graduation when I decided that 22 years of CA was enough, and that it was time for a change.</p><h3>The middle</h3><p>I wasn’t sure what I wanted to study at UC Davis initially when I started school. I was undecided at first, then decided I wanted to pursue healthcare, then finally decided that organic chemistry is my kryptonite.</p><p>I ended up studying computer science and engineering at UC Davis and crammed a engineering degree into 2.5 years (it took me awhile to figure out biology wasn’t for me). Something about the flexibility, creativity and the need to focus I was able to develop while sitting through hours of debugging really made me feel comfortable and at peace. I think my favorite topics were parallel architectures and data engineering.</p><p>Upon graduation in 2018, most of my friends in tech stayed in the Bay Area, what a surprise, but I had wanted something different. I signed my first offer letter with a firm in NY, packed my bags and I was on my way to Brooklyn, NY.</p><h3>The past work</h3><p>I started off my career at Moody’s Analytics where I was a part of the MATR, or technology rotation program for short. I was building ETL pipelines for business intelligence with spark and Kafka for the better part of a year before deciding that finance and risk wasn’t my passion either.</p><p>Maybe a 100 year old corporation wasn’t the right environment for me, so I started interviewing around until I landed at pymetrics. I felt working in a inspired and motivated, tiny but mighty startup would fulfill the inner Silicon Valley native’s tech startup dream in me. Through two years I went from never writing a Rest API endpoint to being a competent backend software engineer. Some of my favorite projects included designing and developing an event driven system with celery and rabbitMQ, and building a SQL data abstraction layer with DBT that fed aggregated data into a ROI dashboard.</p><h3>The current work</h3><p>In 2021 I switched companies again and joined a Healthcare analytics startup, Komodo Health. “To Reduce the Burden of Disease”… what an inspiring mission statement. This vision blended my passion for contributing to the healthcare industry with my skill set in technology.</p><p>I’ve still got the same title: backend software engineer, but the tools and frameworks I’ve been using here are vastly different than they were at my previous gigs. My first major contribution was to take a small FastAPI application and make it production ready. This included a lot of Docker, celery workers, AWS and New Relic. I hope to write more about the new things I’m learning to share some insights I may have gained while working through these problems.</p><h3>My passions</h3><p>The circumstances over the last couple of years have forced me to find new ways to connect with people because of the pandemic. Gone were the days of going clubbing and bar hopping in NYC, until Summer 2021. There were no gyms that were open for over a year in the city either. Instead I had to pick up new sports like scuba diving, snowboarding and badminton.</p><p>It’s such a wonderful thing when you can share all your passions with your significant other. I’ve been blessed with meeting someone this year who shares all these hobbies, a love for traveling and a never quenched curiosity of the world 🥰</p><p>I hope to write more about my passions outside of work, and our little spontaneous getaways or yummy eats that we find in the city as well.</p><p>~~</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68817dda1705" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>