Archive for the ‘tips and tricks’ Category

The Case of a Platform Rebuild from Laravel

This post is a discussion with a colleague who reached out to me requesting for advice on whether to rebuild their successful e-commerce platform whose usage has grown exponentially over the last 18 months.

Advice on Platform Rebuild
Laravel is not Enterprise Ready

My first piece was 90% of platform rebuilds and re-architectures fail, especially since there are always unseen constraints in the new tooling that slows down the process. My approach is always to advice to squeeze as much as you can from your existing framework, language and platform before starting to look elsewhere

While this post is Laravel – specific, the ideas are applicable to any framework, programming language or even mix of technologies

As a Laravel developer who is passionate about architecture and solving scaling challenges, this is a series of questions to drive decision making

  1. Are you on the latest PHP 8.1 and Laravel 9?
    • Uprading to the latest version of PHP and Laravel pulls in the latest performance improvements in the language stack
    • This also applies to the webserver Apache/Nginx
    • Is your database the latest applicable version
    • Server hardware
      • CPU latest generation of processors for the configuration
      • OS patches – remove unused and unneeded services
      • SSD disks for IO bound performance
      • RAM – the more the better
    • Network configuration – unnecessary round trips from the application to the database (see below too)
  2. Is your database and application well tuned? Indexes, reducing the size of requests and number of queries
    • Application tuning is an art that can be taught – for a database heavy application like this case the Eloquent Performance Patterns by is a key resource (https://eloquent-course.reinink.ca/)
    • This also involves removing unused plugins and libraries, and leveraging the framework best practices – Larvel Beyond Crud (https://spatie.be/products/laravel-beyond-crud) and Frontline PHP (https://spatie.be/products/front-line-php) from the team at Spatie are excellent primers
    • The memory usage per request can easily be shown by the Laravel Debug Bar (https://github.com/barryvdh/laravel-debugbar) during development
    • Checking the size of requests and responses may improve performance – send as little data as required for the operation, paginate in the database not the application
    • Add indexes to improve table joins, redesign tables for needs, separate data collection & reporting (denormalization may be needed here)
    • Use Specific API requests for cases where generic default CRUD ones do not perform well
    • Is all that Javascript necessary in the application pages?
    • Is all that that CSS necessary in the application pages?
    • Is the database tuned for the hardware that it is running on?
  3. Are you using the framework tools like queues to offload processing into asynchronous operations via queues
    • At times performance issues may be experienced by users especially in e-commerce setups where actions that can be asynchronous are added into a synchronous workflow slowing down responses to end users e.g., sending a confirmation email (adds 2-5 seconds to the order response) can be done after so the ordering process completes faster for the customer
    • For faster throughput using extensions like Octane can provide the necessary performance boost
    • Tweaking the web server Apache/Nginx to handle more users
    • Load balancing across more than one webserver can provide quick wins
  4. Increasing your database resources – bigger server, tuning the MySQL
    • Computing power is cheap thus a beefier server or more RAM may do the trick depending on whether the deadlocks are CPU/Disk or memory bound
    • If a beefier server does not help, probably load balancing across multiple smaller servers even for stateful vs stateless requests could improve performance
  5. Concurrency using Laravel Vapor and Octane?
    • Vapor is a paid service to bring serverless to the Laravel applications
    • Octane increases the concurrency of request handling though application changes may be needed to cater for the constraints Octane places
  6. Are you profiling your application with tools like Blackfire or Sentry to find performance deadlocks?
    • The performance improvement approach is measure, find the bottleneck, tweak to improve, then rinse and repeat
    • Are there errors or failures that are causing the application to slow down
  7. Have you refactored and cleaned up your data model to match the current reality?
    • As applications evolve there is a need to remove old code, data columns to suit the new reality
    • Refactoring code to match reality removes any unncessary baggage that is carried along
  8. Is your architecture the simplest that it can be – https://future.a16z.com/software-development-building-for-99-developers/ as your organization may not need the complexity of a Fortune 500 or FAANG
  9. There are hidden gems which can also be leveraged to improve your architecture & unearth performance issues
    • Test Driven Development – even if tests are written after the code, unit testing complex algorithms while carrying out end-to-end workflows of critical user paths
    • Design for failure – especially for external services
    • CI/CD – automate deployments to get new features, bug fixes and enhancements into production as fast as possible
    • Setup staging sandboxes to test out ideas and tweaks
    • Monitor your production application service health – Laravel Health (https://spatie.be/docs/laravel-health/v1/introduction) provides an excellent starting poing

When all else fails and a platform rebuild is necessary the Strangler Fig Pattern is a great way forward – replace different parts of the application as needed replacing them with newer architectural pieces referred Legacy Application Strangulation : Case Studies (https://paulhammant.com/2013/07/14/legacy-application-strangulation-case-studies/)and Strangler Fig Application (https://martinfowler.com/bliki/StranglerFigApplication.html)

What are you thoughts and suggestions? What has worked for you and what pit falls did you find? Any additional advice?

Advertisement

Geek Tools – My Keyboard Journey

As a software engineer my days and nights are driven by the need to type instructions for a computer to execute into text files. Thus the keyboard is my primary tool for this input.

My primary workhorse over the last couple of years has been a MacBook Pro laptop and now majority of the time, I use it in clam shell (closed) with an external monitor and mouse. An external keyboard is critical in this mode, so sharing my journey over time

Regular Computer Keyboards

I started with the DELL Keyboard and it just works when you need it

Apple Keyboards

I purchased the full wired keyboard and the Magic Keyboard 2 – these are excellent low profile keyboards for use anywhere and I would totally recommend them. The full wired keyboard is best for a fixed location, while the Magic Keyboard is a lightweight travel friendly keyboard with great battery life, can be used during charge and the key responses are excellent, though I find it a little low and hard on my hands

Logitech MX Keys

I started out with the MX Keys and later got the MX mini (as the full keyboard would not fit on my standing desk with the mouse), and I should say these are awesome keyboards. They are so alike, one just having a numeric keypad while the other does not. The build quality is excellent, feel bulkier and more solid the Apple keyboards, love the 3 computer switch capabilities by just pressing a key, and the travel is just right (like Golidilock’s porridge). They are priced similar to the Apple keyboards, but IMO they provide more value

Mechanical Keyboards

I have had the chance to try out the Keychron K6, and I love them – more travel than the MX Keys but love the RGB backlighting, and the tactile feedback. I am currently in search for a low profile mechanical to try out, with an eye on the Keychron K3, as I await feedback

I am also eyeing the Numpy Air75 (https://nuphy.com/collections/keyboards/products/air75) and the Logitech MX Mechanical Mini (https://www.logitech.com/en-us/products/keyboards/mx-mechanical.html) that is before I start building my own custom keyboards …

UPDATE – September 2022: I got myself an RGB backlit Keychron K7 with Gaeton brown switches (which are very quiet) and I am in love. However I should have purchased the K3, which I am looking forward to so that I have the extra line of functions without needing to keep pressing the Function switch keys

UPDATE – April 2023: I finally got my hands on the RGB backlit Keychron K3 with Gaeton brown switches plus the extra line of keys, I am sooo in love.

Keychron K3 (bottom) compared with the K7

Split Keyboards – The Bucket List

These I have on my bucket list with https://ultimatehackingkeyboard.com/ leading the pack – will see if 2022 gives me the opportunity to try this type of keyboards out

What is working for you, do share your experiences and ideas, I am a work in progress and continously experimenting to find those tools that make me happy

My Code Review Workflow

My role involves reviewing code written by different members of my team, which is an important process in the software delivery lifecycle. In certain cases, code reviews turn into gatekeeping which does not deliver the intended value for the process

The reason for code reviews

  1. Get a shared understanding of the code submitted – an opportunity to share, learn and collaborate
  2. Find opportunities to improve the code and what it is doing – refactoring
  3. Find edge cases that may not have been covered
  4. Verify that the code does what is expected

I just thought I would share my PR review approach and I hope it may help others here

  1. Read through the code changes across the files in the GitHub/GiLab or version control UI – this helps me get a sense of files which should not be there, too many files, too few files etc
  2. Pull the PR locally on my machine – Jetbrains IDEs and VS Code have pull request views and functionality if you are not a cli guru like yours truly
  3. Run the code and test the features as documented both happy path and some random abrupt paths

The improvements we are going to add to our projects (still looking for ideas here)

  1. Automated code checking for formatting and linting

I tend to use Firefox developer edition (set to always start in private mode) for web stuff to view it in a clean browser. Chrome is the new Internet Explorer 6 (the most painful growth phase of the web)

What is your code review workflow, what tips and tricks have you used to make it smoother and more streamlined?

UPDATE 1: November 4, 2021 – excellent reference on by Chelsea Troy https://chelseatroy.com/2019/12/18/reviewing-pull-requests/

Voice of the ElePHPant Podcast – PHP, Technology Journey, Opensource, Java

I am excited to have been hosted on the Voices of the Elephant podcast by Cal Evans

https://voicesoftheelephpant.com/2020/06/23/interview-with-stephen-s-musoke/

Talking about my technology journey, opensource, Java, PHP (of course) and what I am doing with it in Uganda and Africa

Drinking Healthy with Locally Available Options

The lockdown has forced me to slow down, and over time pickup and implement some of the local knowledge for drink options to help reduce my sugar intake – I take about 5 cups of tea a day, so need to find other ways to compensate.

I have been lucky to also have ample space in which to plant some herbs and spices, I am searching for more if you have and are willing to share

This post is to share what I have managed to get so far and will keep updating – in addition to recipies

  1. Kombucha (https://en.wikipedia.org/wiki/Kombucha) – fermented tea drink which I leave for 2 weeks to get to the taste that I (and now the rest of the brood) like
    • Preparation:
      • Boil 20l of water with add 200g of tea leaves
      • Leave to cool till cold, filter out the tea leaves, add 0.5kg of sugar per 5 liters of water
      • Add the kombuca mushroom in a dark colored bucket, and put in a cool place without direct sunlight
      • Open once every 3-4 days to let breathe
      • After 2 weeks, remove, keep in white jerrycans in the fridge, serve cold
    • The bucket and handling have to be done very carefully being cold can be an easy transmission mechanism for typhoid, dysentry and other water borne diseases
    • Clean the mushroom, by removing any seemingly dead parts, usually very dark colored and not consistent with the mushroom. It keeps regenerating so these become evident
    • Leaving it longer than 3 weeks leads to more fermentation giving it a more alcholic taste
    • A friend of mine with very low alcohol tolerance got a hangover from a glass of my 2 week old kombucha
    • You can leave it for varying periods of time depending on your taste buds
    • If you do not have a fridge, you can prepare multiple buckets maturing at different times to have consistent supply
  2. Tumeric, lemon and ginger mix
    • Preparation: boil 200g of tumeric, 50g ginger in about 5 liters of water, add 4 lemons to taste
    • This one we usually add to kombucha to add a different dimension in taste and flavor
  3. Munanansi – this is a new addition with the current low cost of pineapples
    • Preparation (in testing):
      • Boil a 1.5kg pineapple with peels cut into pieces, 50g of tea leaves, 200g of sugar (honey can also be used) and 100g of ginger in 20 liters of water
      • Leave to cool for at least 18 hours which improves the flavor, probably due to the pineapples and ginger settling into the juice
      • Filter and put in the fridge to drink serving cold
    • We are testing using a whole pineapple instead of just the peels so that we can get more juice, rather than the 1 liter we get from just the peels
  4. Tamarind juice
    • Preparation:
      • Place tamarind seeds in water and leave overnight
      • Squeeze the covering of the seeds which has loosened, using cheesecloth or another appropriate strainer
      • Add honey to taste
    • This can be drank alone, but is a great addition to kombucha which already has its own flavor
  5. Mululuza – commonly used for the treatment of malaria in Buganda
    • Preparation:
      • Fill a pan with leaves and add 5cm of water to cover the leaves then boil for 30min
      • Leave to cool and keep in the fridge
    • Tend to add this to tamarind, munanasi or kombucha which have their own flavors, so adds a sourish dimension to the taste
  6. Rosemary – a common addition to tea and meals for flavor, however we have started eating 4-5 leaves per person every morning to start the day
  7. Lime basil (known local name kakuba nsiri) – I add these leaves to my hot tea/coffee drink about 4-5 leaves per cup
  8. Coming soon: moringa and aloe vera (will update when we start to try these out)

Please share your local herb drink and the procedure for preparing it to help build the knowledge

Some photos showing some examples of the preparation steps above

2020-06-07 09.11.44
Munanansi fireplace preparation
2020-06-07 09.11.56
Munanansi preparation
2020-05-07 13.50.23
Tamarind being soaked in water
2020-06-05 18.11.02
Lime basil
2020-04-03 16.20.21
Mululuza after boiling
2020-04-12 18.29.22
Healthy kumbucha plant with bubbles showing its breathing and alive
2020-03-01 18.57.13
kumbucha in bucket
2020-03-01 19.10.50
kumbucha – clearning removing dead parts
%d bloggers like this: