4 Nov 2026
SWE notes 2
To Read
https://www.janestreet.com/tech-talks/system-jitter-and-where-to-find-it
Code Reviews
I LOST ALL MY PROGRESS
https://google.github.io/eng-practices/review/reviewer/looking-for.html
prevent premature optimisation
you should check the tests for false positives
edit your todo comments
major style changes shouldnt be combined with major other changes
For example, you might see only four new lines being added, but when you look at the whole file, you see those four lines are in a 50-line method that now really needs to be broken up into smaller methods.
It’s also useful to think about the CL in the context of the system as a whole. Is this CL improving the code health of the system or is it making the whole system more complex, less tested, etc.? Don’t accept CLs that degrade the code health of the system. Most systems become complex through many small changes that add up, so it’s important to prevent even small complexities in new changes.
In doing a code review, you should make sure that:
- The code is well-designed.
- The functionality is good for the users of the code.
- Any UI changes are sensible and look good.
- Any parallel programming is done safely.
- The code isn’t more complex than it needs to be.
- The developer isn’t implementing things they might need in the future but don’t know they need now.
- Code has appropriate unit tests.
- Tests are well-designed.
- The developer used clear names for everything.
- Comments are clear and useful, and mostly explain why instead of what.
- Code is appropriately documented (generally in g3doc).
- The code conforms to our style guides.
Pytest
https://docs.pytest.org/en/stable/getting-started.html
Microservices
https://martinfowler.com/articles/microservices.html
In short, the microservice architectural style 1 is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.
You only use what you need. You apply SOLID on your code base as a whole. This is good because you'll make it harder for different agents to mess with different parts of the code.
RabbitMQ
https://www.rabbitmq.com/tutorials/tutorial-one-python
RabbitMQ is a message broker: it accepts and forwards messages. You can think about it as a post office: when you put the mail that you want posting in a post box, you can be sure that the letter carrier will eventually deliver the mail to your recipient. In this analogy, RabbitMQ is a post box, a post office, and a letter carrier.
The major difference between RabbitMQ and the post office is that it doesn't deal with paper, instead it accepts, stores, and forwards binary blobs of data ‒ messages.
A message broker that sits inside your internal backend architecture to pass data and tasks asynchronously between different internal services or worker processes via queues.
#!/usr/bin/env python
import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
#create a queue
channel.queue_declare(queue='hello', durable=True, arguments={'x-queue-type': 'quorum'})
channel.basic_publish(exchange='',
routing_key='hello',
body='Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close() #will tell you that the network buffer is actually clear
use cases:
RabbitMQ (offload long running tasks)
Decoupling Microservices (multiple microservices can respond to the same event)
Traffic spike buffering (load levelling)
Guaranteed retry (get from DLX)
unittests
https://docs.python.org/3/library/unittest.mock-examples.html
The reason unittest.mock exists is that sometimes you want to test your Python code without executing everything your code depends on.
from unittest.mock import Mock
# Create a fake email service
fake_email = Mock()
trade = {"status": "FAILED"}
# Run our actual function
process_trade(trade, fake_email)
email_service.send("Trade failed!")
and this will help you check sideeffects
fake_email.send.assert_called_once_with(
"Trade failed!"
)
database.get_user.return_value = 42
print(database.get_user())
# 42
database.get_user.side_effect = ValueError("User not found")
database.get_user()
# Raises ValueError: User not found