Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REDIS_URL=redis://127.0.0.1:6379
REDIS_DATABASE=0
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Environment Configuration
# Copy this file to .env in your project root

# Cache Configuration
FORCE_FRESH_LATEST=true

# Optional: Override cache durations
# DEFAULT_CACHE_MS=300000
# LATEST_BLOCK_CACHE_MS=60000

# Development vs Production
# FORCE_FRESH_LATEST=false # For development (faster)
# FORCE_FRESH_LATEST=true # For production (accurate)
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# dependencies
/node_modules
.esbuild
/.idea/modules.xml
/.idea/backend-assignment-btcenergy.iml
# dependencies
/node_modules
.esbuild
/.idea/modules.xml
/.idea/backend-assignment-btcenergy.iml
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
16
49 changes: 49 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Serverless Offline",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/serverless",
"args": [
"offline",
"start",
"--httpPort=4000",
"--host=0.0.0.0"
],
"cwd": "${workspaceFolder}",
"env": {
"NODE_OPTIONS": "--inspect=9230"
},
"console": "integratedTerminal",
"autoAttachChildProcesses": true,
"skipFiles": [
"<node_internals>/**"
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/**/*.js"
],
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
]
},
{
"name": "Attach to Serverless",
"type": "node",
"request": "attach",
"port": 9230,
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"skipFiles": [
"<node_internals>/**"
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/**/*.js"
]
}
]
}
34 changes: 34 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "compile",
"group": "build",
"label": "npm: compile",
"detail": "tsc -p . --noEmit"
},
{
"type": "npm",
"script": "debug",
"group": "build",
"label": "npm: debug",
"detail": "node --inspect=9229 node_modules/serverless/bin/serverless.js offline start --httpPort=4000 --host=0.0.0.0",
"isBackground": true,
"problemMatcher": {
"pattern": {
"regexp": "^\\s*at\\s+(.*?)\\s+\\((.*?):(\\d+):(\\d+)\\)$",
"file": 2,
"line": 3,
"column": 4,
"message": 1
},
"background": {
"activeOnStart": true,
"beginsPattern": "^.*Serverless: Starting Offline.*$",
"endsPattern": "^.*offline: Offline \\[http for lambda\\] listening on.*$"
}
}
}
]
}
191 changes: 95 additions & 96 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,96 +1,95 @@
# Backend Engineer Technical Assignment
## Introduction
This assessment aims to assess the technical, analytical, and collaboration skills of
the candidates for backend development positions in Sensorfact.

In this assignment, we included a few of the technologies that we use in our
existing products:

- **GraphQL:**
Within Sensorfact we expose most of our data regarding measurements, machine
specific configuration and industry knowledge via a GraphQL API.
- **TypeScript:**
A big part of our code is written in plain JavaScript. All
new projects use TypeScript, because we like the benefits that the type system
offers us during development, reviews, and testing.

## Process & Guidelines

>- **We aim to timebox the assignment to 4 hours**, but feel free to dedicate as much time as you consider necessary
>- Make a conscious decision on what you want to focus on: it's ok if you
cannot complete the entire assignment.
>- Send us your solution before the technical interview: link to a repository.
You can, for example, fork this repository.
>- The assignment includes a description of a problem to solve, which could potentially lack
details. Feel free to make assumptions if needed, or contact us for clarification if you consider it necessary.
>- Take this assignment as an opportunity to show us your style: what you like to
work on, what you find important, how you address problems,etc.
>- Feel free to use any tool you'd like, that includes AI assistants as well.
We want you to work with the tools you know from your Day2Day work but expect us to dive deep with you into the decision making behind adding / using certain logic.
>- **During the technical interview, we invite you to present your solution and discuss
it together as a team**: which decisions you took and why, questions about specific parts of the code,
libraries you have used, how easy and maintainable is the code,etc.

## Problem to solve (an imaginary one, of course ;))

Sustainability is starting to take a key role in every product or solution launched into the market, and software
systems are not an exception. It is not enough anymore to create and deploy in time complex and innovative
systems which bring value to customers; they also need to be efficient. They need to
be sustainable and consume the minimum amount of resources in their operations.

As you probably have heard, one of the principal arguments against using Bitcoin is the amount of energy needed to keep
the system running. To evaluate the sustainability of the blockchain network in which Bitcoin runs, we
want to create a platform to monitor the energy spent on financial transactions using Bitcoin.

The platform will visualize the energy consumed by the network and potentially calculate energy waste. Our frontend
development team will need an API (preferably GraphQL) to connect to which will provide this information. The platform should
be able to perform the following operations (already sorted by priority):

- Provide the energy consumption per transaction for a specific block.
- Provide the total energy consumption per day in the last `x` number of days.
- Advanced Feature: Optimize the number of calls made to the Blockchain API to avoid asking for the
same information multiple times.
- Expert Feature: Provide the total energy consumption of all transactions performed by a specific wallet address.

Even if it is too soon in the product's lifetime to think about non-functional requirements, it will be beneficial to
build it considering that we hope to scale the solution and avoid significant refactoring.

## Assumptions

**- You can use a simple model of the BTC network: the network is composed of blocks (each block identified by a unique `hash` value
or a block index). Each block contains a set of transactions, each transaction also has a unique `hash` by which it can be identified.**
- Every transaction takes up a variable amount of storage space inside the block, indicated by the `size` field (in bytes).
- Assume that the energy cost per byte is 4,56 KwH.
- You can use the public Blockchain API from blockchain.com to retrieve information
(https://www.blockchain.com/explorer/api/blockchain_api), for example:
- Latest block: https://blockchain.info/latestblock
- Information of blocks in a day: https://blockchain.info/blocks/$time_in_milliseconds?format=json
- Information of a single block: https://blockchain.info/rawblock/$block_hash
- Information of a single transaction: https://blockchain.info/rawtx/$tx_hash
- Information on transactions for a specific wallet address: https://blockchain.info/rawaddr/$bitcoin_address

## Project code
This project is comes with a pre-configured GraphQL server, hosted as a serverless
function to get you started on the assignment. However, feel free to write your
own implementation if you prefer.

## Running the project
Requirements:
- NodeJS 16.x (run `nvm use` in root folder)
- Yarn cli
- Serverless framework: run `npm install -g serverless`

Install dependencies:

```sh
yarn
```

Run the serverless function in offline mode:

```sh
yarn start
```

The server will be ready at: `http://localhost:4000/graphql`

# Backend Engineer Technical Assignment
## Introduction
This assessment aims to assess the technical, analytical, and collaboration skills of
the candidates for backend development positions in Sensorfact.

In this assignment, we included a few of the technologies that we use in our
existing products:

- **GraphQL:**
Within Sensorfact we expose most of our data regarding measurements, machine
specific configuration and industry knowledge via a GraphQL API.
- **TypeScript:**
A big part of our code is written in plain JavaScript. All
new projects use TypeScript, because we like the benefits that the type system
offers us during development, reviews, and testing.

## Process & Guidelines

>- **We aim to timebox the assignment to 4 hours**, but feel free to dedicate as much time as you consider necessary
>- Make a conscious decision on what you want to focus on: it's ok if you
cannot complete the entire assignment.
>- Send us your solution before the technical interview: link to a repository.
You can, for example, fork this repository.
>- The assignment includes a description of a problem to solve, which could potentially lack
details. Feel free to make assumptions if needed, or contact us for clarification if you consider it necessary.
>- Take this assignment as an opportunity to show us your style: what you like to
work on, what you find important, how you address problems,etc.
>- Feel free to use any tool you'd like, that includes AI assistants as well.
We want you to work with the tools you know from your Day2Day work but expect us to dive deep with you into the decision making behind adding / using certain logic.
>- **During the technical interview, we invite you to present your solution and discuss
it together as a team**: which decisions you took and why, questions about specific parts of the code,
libraries you have used, how easy and maintainable is the code,etc.

## Problem to solve (an imaginary one, of course ;))

Sustainability is starting to take a key role in every product or solution launched into the market, and software
systems are not an exception. It is not enough anymore to create and deploy in time complex and innovative
systems which bring value to customers; they also need to be efficient. They need to
be sustainable and consume the minimum amount of resources in their operations.

As you probably have heard, one of the principal arguments against using Bitcoin is the amount of energy needed to keep
the system running. To evaluate the sustainability of the blockchain network in which Bitcoin runs, we
want to create a platform to monitor the energy spent on financial transactions using Bitcoin.

The platform will visualize the energy consumed by the network and potentially calculate energy waste. Our frontend
development team will need an API (preferably GraphQL) to connect to which will provide this information. The platform should
be able to perform the following operations (already sorted by priority):

- Provide the energy consumption per transaction for a specific block.
- Provide the total energy consumption per day in the last `x` number of days.
- Advanced Feature: Optimize the number of calls made to the Blockchain API to avoid asking for the
same information multiple times.
- Expert Feature: Provide the total energy consumption of all transactions performed by a specific wallet address.

Even if it is too soon in the product's lifetime to think about non-functional requirements, it will be beneficial to
build it considering that we hope to scale the solution and avoid significant refactoring.

## Assumptions

**- You can use a simple model of the BTC network: the network is composed of blocks (each block identified by a unique `hash` value
or a block index). Each block contains a set of transactions, each transaction also has a unique `hash` by which it can be identified.**
- Every transaction takes up a variable amount of storage space inside the block, indicated by the `size` field (in bytes).
- Assume that the energy cost per byte is 4,56 KwH.
- You can use the public Blockchain API from blockchain.com to retrieve information
(https://www.blockchain.com/explorer/api/blockchain_api), for example:
- Latest block: https://blockchain.info/latestblock
- Information of blocks in a day: https://blockchain.info/blocks/$time_in_milliseconds?format=json
- Information of a single block: https://blockchain.info/rawblock/$block_hash
- Information of a single transaction: https://blockchain.info/rawtx/$tx_hash
- Information on transactions for a specific wallet address: https://blockchain.info/rawaddr/$bitcoin_address

## Project code
This project is comes with a pre-configured GraphQL server, hosted as a serverless
function to get you started on the assignment. However, feel free to write your
own implementation if you prefer.

## Running the project
Requirements:
- NodeJS 16.x (run `nvm use` in root folder)
- Yarn cli
- Serverless framework: run `npm install -g serverless`

Install dependencies:

```sh
yarn
```

Run the serverless function in offline mode:

```sh
yarn start
```

The server will be ready at: `http://localhost:4000/graphql`
Loading