Model a simple banking system: - `accounts` table: - `id`, - `owner_id`, - `currency`, - `created_at`. - `transactions` table: - `id`, - `account_id`, - `amount`, - `created_at`. **Requirements:** 1. Write SQL to create the schema with necessary constraints (NOT NULL, FK, CHECK on non-zero `amount`). 2. Write a query: - to get the current account balance by `account_id` (sum of amount). 3. Harder: support debit/credit (double entry). Cleanup
Golang
Overall impression of the interview, candidate's level, recommendations
How does the garbage collector work in Go? Describe the phases and algorithm.
How can database search be optimized? What are indexes and what is their complexity?
В чем преимущества goroutines перед OS threads?
Tell us about the Go scheduler. How does it work? What is hand-off?
What synchronization primitives are available in Go? What is the difference between Mutex and RWMutex? When to use atomics?
How is the map in Go structured? Tell about its internal structure, buckets, collisions.
3. Усложнение: поддержать дебет/кредит (двойная запись). Cleanup CREATE TABLE accounts ( id BIGSERIAL PRIMARY KEY, owner_id BIGINT NOT NULL, currency VARCHAR(3) NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT now() ); CREATE TABLE transactions ( id BIGSERIAL PRIMARY KEY, account_id BIGINT NOT NULL REFERENCES accounts(id), amount NUMERIC(18,2) NOT NULL CHECK (amount <> 0), created_at TIMESTAMP NOT NULL DEFAULT now() ); CREATE INDEX idx_transactions_account_id ON transactions(account_id); SELECT COALESCE(sum(amount), 0) AS balance FROM transactions WHERE account_id = :account_id; ALTER TABLE transactions ADD COLUMN type VARCHAR(6) NOT NULL CHECK (type IN ('debit', 'credit')); ALTER TABLE transactions DROP CONSTRAINT transactions_amount_check, ADD CONSTRAINT transactions_amount_check CHECK (amount > 0); SELECT COALESCE( SUM(CASE WHEN type = 'credit' THEN amount WHEN type = 'debit' THEN - amount ) AS balance FROM transactions WHERE account_id = :account_id;
Model a simple banking system: - `accounts` table: - `id`, - `owner_id`, - `currency`, - `created_at`. - `transactions` table: - `id`, - `account_id`, - `amount`, - `created_at`. **Requirements:** 1. Write SQL to create the schema with necessary constraints (NOT NULL, FK, CHECK on non-zero `amount`). 2. Write a query: - to get the current account balance by `account_id` (sum of amount). 3. Harder: support debit/credit (double entry). Cleanup.