Issue #39: 10 Reads, A Handcrafted Weekly Newsletter For Software Developers

The time to read this newsletter is 145 minutes.

Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat. – Sun Tzu

  1. Using the hunger I experienced as a kid to teach mine about generosity: 10 mins read. We all become too specific and choosy when it comes to helping others. We don’t want to offer the best we have. These are the best words I have read in a long time

    > When you give the best you have to someone in need, it translates into something much deeper to the receiver. It means they are worthy.
    >
    > If it’s not good enough for you, it’s not good enough for those in need either. Giving the best you have does more than feed an empty belly—it feeds the soul.

  2. Calendar Versioning: 10 mins read. CalVer is a versioning convention based on your project’s release calendar, instead of arbitrary numbers.

  3. Doing a database join with CSV files: 10 mins read. xsv is a tool that you can use to join two CSV files. The author shows examples of inner join, left join, and right join. Very useful indeed.

  4. SQL, NoSQL, and Scale: How DynamoDB scales where relational databases don’t: 20 mins read. This post provides a good overview on why RDBMS fail to scale and how DynamoDB can be used to build web scale applications.

  5. Why databases use ordered indexes but programming uses hash tables: 15 mins read. This post explains why databases uses b-tree and programs use hash tables. The main reasons shared by author are:

    1. Ordered data structures perform much better when n is large. With hash based collections, one collision can cause O(n) performance. Range queries becomes O(n) if implemented using hash tables
    2. Ordering helps in indexes and we can reuse one index in multiple ways. With hash tables, we have to implement separate indexes
    3. Ordered collection achieve locality of reference.
  6. Xor Filters: Faster and Smaller Than Bloom Filters: 15 mins read. In this post, author talks about Xor filters to solve problems where you need to check whether an item exist in cache or not. Usually we solve such problems using a hash based collection but this can be solve using Xor filters as well. Xor filters take a bit longer to build, but once built, it uses less memory and is about 25% faster. Bloom filters and cuckoo filters are two other common approaches to solve these kind of problem as well.

  7. Distributed architecture concepts I learned while building a large payments system: 20 mins read.The author described important distributed system concepts. He covers consistency, durability, SLA, and many other concepts.

  8. From 15,000 database connections to under 100: DigitalOcean’s tale of tech debt: 20 mins read. This post by Digital Ocean is a must read for every developer. They talked about how they incrementally moved their legacy DB based message queue to the one based on RabbitMQ. Key points from the post are:

    1. Like GitHub, Shopify, and Airbnb, DigitalOcean began as a Rails application in 2011. The Rails application, internally known as Cloud, managed all user interactions in both the UI and public API. Aiding the Rails service were two Perl services: Scheduler and DOBE (DigitalOcean BackEnd). Scheduler scheduled and assigned Droplets to hypervisors, while DOBE was in charge of creating the actual Droplet virtual machines. While the Cloud and Scheduler ran as stand-alone services, DOBE ran on every server in the fleet.
    2. For four years, the database message queue formed the backbone of DigitalOcean’s technology stack. During this period, we adopted a microservice architecture, replaced HTTPS with gRPC for internal traffic, and ousted Perl in favor of Golang for the backend services. However, all roads still led to that MySQL database.
    3. By the start of 2016, the database had over 15,000 direct connections, each one querying for new events every one to five seconds. If that was not bad enough, the SQL query that each hypervisor used to fetch new Droplet events had also grown in complexity. It had become a colossus over 150 lines long and JOINed across 18 tables.
    4. When Event Router went live, it slashed the number of database connections from over 15,000 to less than 100.
    5. Unfortunately, removing the database’s message queue was not an easy feat. The first step was preventing services from having direct access to it. The database needed an abstraction layer.
    6. Now the real work began. Having complete control of the event system meant that Harpoon had the freedom to reinvent the Droplet workflow.
    7. Harpoon’s first task was to extract the message queue responsibilities from the database into itself. To do this, Harpoon created an internal messaging queue of its own that was made up of RabbitMQ and asynchronous workers. As of this writing in 2019, this is where the Droplet event architecture stands.
  9. Why do we need distributed systems?: 10 mins read. We build distributed systems because
    1. Distributed systems offer better availability
    2. Distributed systems offer better durability
    3. Distributed systems offer better scalability
    4. Distributed systems offer better efficiency
  10. On Kubernetes, Hybrid and Multi-cloud: 15 mins read. The key points in the post are:
    1. The first thing to consider is agility—cloud services offer significant advantages on how quickly you can spin infrastructure up and down, allowing you to concentrate on creating value on the software and data side.
    2. But the flip side of this agility is our second factor, which is cost. The agility and convenience of cloud infrastructure comes with a price premium that you pay over time, particularly for “higher level” services than raw compute and storage.
    3. The third factor is control. If you want full control over the hardware or network or security environment that your data lives in, then you will probably want to manage that on-premises.

Tools I discovered this week

  1. Broot: It is a CLI tool that you can use to get an overview of a directory, even a big one. It is written in Rust programming language. I use it as an alternative to tree command.
  2. xsv: It is a CLI tool for working with CSV files. It can concatenate, count, join, flatten, and many other things. It is Swiss army tool for CSV. It is written in Rust programming language.
  3. pigz: A parallel implementation of gzip.

Video of the week

The 21 Lessons From “The Tao of Charlie Munger”

I read The Tao of Charlie Munger book this weekend and following are my favourite lessons from it. It is a book that you can read in half a day.

  1. Focus on your circle of competence. I have written about it in LIL #3.
  2. Diversification makes no sense for someone who knows what they are doing. It is a protection against ignorance.
  3. You should bet heavily when odds are in your favour.
  4. Patience is the key to becoming a successful investor. I succeed because I have a long attention span.
  5. Overconfidence destroys even the smartest among all.
  6. Wait for the right opportunity. All of the humanity problem stems from the man’s inability to sit quietly in a room alone.
  7. Try not be stupid rather than trying to be intelligent.
  8. Fear is essential to make people work.
  9. A great business at a fair price is superior to a fair business at a great price.
  10. There is no master plan. You have to keep iterating and improving.
  11. Spend each day trying to be a little wiser that you were when you wake up.
  12. Good people find other good people.
  13. Know big ideas from different disciplines.
  14. Watch out for people who always confidently answer questions about which they don’t have any real knowledge.
  15. Admit your stupidity
  16. Specialization protects us from the competition.
  17. Live within your means.
  18. To be successful in something, we need to be passionately interested in it.
  19. If you don’t need something, you don’t have to buy it. Be frugal.
  20. Become a learning machine.
  21. In marriage, you shouldn’t look for someone with good looks and character. You should look for someone with low expectations.

Why GraphQL? 8 Reasons After Reading 13 GraphQL Case studies

GraphQL is a query language built by Facebook. It is an alternative to building REST APIs. In the last few years it has become popular and there are many big organisations like Facebook, Github, NewYork Times, Shopify, Walmart Labs, and many others that are using it to build their web applications.

GraphQL is a query language and a runtime system. Clients form requests (called queries and mutations) by using the GraphQL query language, and the GraphQL server executes the request and returns the data in a response. Unlike REST APIs, which expose a different endpoint for each resource object, a GraphQL API makes all data available at a single endpoint. A client specifies exactly the data that it wants, and the server responds with only that data.

For last few months I am thinking to spend time learning about GraphQL but before I get deeper into GraphQL I wanted to understand why many organisations are adopting it. So, I spent a day reading GraphQL case studies mentioned on the GraphQL website.

Continue reading “Why GraphQL? 8 Reasons After Reading 13 GraphQL Case studies”

Using Redis Streams To Implement Near Cache Invalidation

Early last year I was working on an application that kept data in a near cache. I will not delve into reasons why we used near cache other than that we had strict performance requirements that required data closer to the compute.

Near cache for those who have not heard this term is a smaller local(in the same process as your application) cache that stores most recently used or most frequently accessed data. So, if you are running a Java application near cache could be as simple as a ConcurrentHashMap or you can use libraries like Cache2k or Caffeine to implement a near cache.

You can read the complete post on Xebia Engineering Medium publication.

LIL #3: Lessons I Learnt This Week

Welcome to the third post of lessons I learnt(LIL) series. I had a good week and I am content with what I achieved. Telling yourself repeatedly that life is not a race and you can take your time and be at peace with yourself is a powerful feeling. There were two thoughts that repeatedly came to my mind this week that I wanted to share with you this week.

Continue reading “LIL #3: Lessons I Learnt This Week”

The 5 Minute Introduction to DuckDB: The SQLite for Analytics

A couple of weeks back I learnt about DuckDB while going over DB Weekly newsletter. It immediately caught my attention as I was able to quickly understand why need for such a database exist. Most developers are used to working with an embedded file based relational database in their local development environment. Most popular choice among embeddable RDBMS is SQLite. Developers use embeddable databases because there is no set up required and they can get started quickly in a couple of minutes. This enables quick prototyping and developers can quickly iterate on business features.

DuckDB is similar to SQLite in the sense it is also designed to be used as an embeddable database. Developers can easily include it as a library in their code and start using it. Later in this post, I will cover how we can use DuckDB with Python.

Continue reading “The 5 Minute Introduction to DuckDB: The SQLite for Analytics”

Problem Details for HTTP APIs with Spring Boot

If you are building REST APIs you will understand that HTTP status codes at times are not sufficient to convey enough information about an error. There is a specification RFC 7807 that defines how you can return error information back to the client. The way it works is by identifying a specific type of problem with a URI.

To make it more clear let’s suppose you are building a todo list application where you want to build API to move items from one list to other. If the target list has a cap on maximum items it can hold and you try to move an item from source list to target list the list then you should get an exception.

If all you have is HTTP status code then you can just return HTTP status code 403 forbidden. However, it does not give the API client enough information about why the request was forbidden. Different developers have solved this problem differently by building their application specific error objects. Problem Details for HTTP APIs specification solves this problem by defining a standard format in which API error response should be returned.

Continue reading “Problem Details for HTTP APIs with Spring Boot”