Skip to content

Instantly share code, notes, and snippets.

View adamgarcia4's full-sized avatar

Adam Garcia adamgarcia4

  • Atlanta, Georgia
View GitHub Profile
Service Java-to-Go Port — Plan
Owner — WatchTower platform engineering
Status — Draft
Design refs — Data layer re-architecture, Rules engine HLD, Capacity estimate, Pipeline category mapper
Tasks — see TASKS.md
TL;DR
Replace apps/service with one Go codebase and one image, but run that image in independently scalable api, ingest, rules, and projection roles.
Keep PostgreSQL as the durable source of truth and preserve the current REST, SSE, gRPC, Kafka, Valkey, and database contracts until parity tests prove a deliberate change.
Port by deep module, not Java class: bronze consumption, silver projection, pipeline evaluation, rules, query, and realtime each own a small interface and a named table set.
The highest-value throughput work is database and execution-path work: micro-batching, exact per-partition cursors, conflict-driven idempotency, an incremental-FSM fast path, set-based rules, durable outboxes, incremental gold projection, and bounded concurrency.

DSA Coding Challenge — Kubernetes Horizontal Scaling Algorithm

Background

Kubernetes has a built-in Horizontal Pod Autoscaler (HPA) that watches a metric — like requests per second — and scales the number of replicas up or down to keep the metric at a target level. For example, if your target is 100 RPS per pod and you're seeing 400 RPS total, you want 4 replicas. If you're seeing 50 RPS total, you'd want 1 — but never below your configured minimum.

You're going to implement the core scaling decision as a pure function. No Kubernetes API calls — just math and bounds enforcement.

Problem Statement

// Write an application that tells us which ticker has a greater open price
const getExpensiveStock = async () => {
console.log("============ START ===========")
// Problem Decomposition
// 1. Define Names of Stocks to pull
const ticker1 = undefined
const formattedTicker1 = ticker1
const ticker2 = undefined
const formattedTicker2 = ticker2
const { restClient } = require("@polygon.io/client-js");
const rest = restClient("rt65BvAyd7yr219qQ7M9pHIe7qosYdwl");
const getOpenPrice = async (ticker) => {
if (ticker === 'GOOG') {
return 1000
}
if (ticker === 'AAPL') {
const swaggerValidationMiddleware =
(routeConfig: ISwaggerParams) => {
const AdditionalResponses: { [statusCode: string]: ResponseConfig } = {
422: {
description: 'Invalid input',
content: {
'application/json': {
schema: z.object({
code: z.string(),
message: z.string(),
D*F``n`@A`pc'BP>Sp>O9РM>|N ܚc( Q%VTD B$Q`ŸwӬ"%ڏ,",zJ#$QDU@ȈJΒ)4Xh,e ߿~dD!OHw=
?
"DMP b
buOP!>.(hHpmĮJD`Lt~P e1I>HA~N#LNW}Lu/vѻL͝-TѪ)S!3D"a.Әr=}р1U0@TW!MBGDz?BagЃEިI߫[-ΤD2^p +];AXCwEϢJuS?c oWy j 1\
;?YHD ᢸ##ŒBw=zLxE5u e"J%(TySO% d M d+&Z[5 zD
>q.tynzJ^[Vjc~M768صDʑ&Yr*ܨk2%#;ۿˈ&:ަ`X[ND
.ƞp@ף̹M^*d(T/6u\~!F߯mC\~/CG|(`DzVV&i&iD
ޞpDv]^2[ݧ֮٦x)ѣy|dFqDƇ%kcB .|'hQP' 3MmD1p ުH,B#Wp2\ iOҵ?PAQ $]e=Rֳ%D#9\zs֟vӟX4#2-FCH*Y=~JLQjdAQH
UNh f~p֒EDiV/@@>@܉zc^?29+]o-o3JpHvDV%~W8BrD&aʞ2f<Dx{\q۷Z^hrU,#!Tz~bwRrQ6d98T A8VD3 ΘА;j٩)V#)e.(
NjuEF,$Mo(G$偒=?DA lʌ,GF+=LҟҌuoΝ`l!r|uzK-خO 􇝇/HWv4DK:|-˅/'䝤7OZuDS̯hP?͙P墎'az<8 6 䁌KKʇDC2^2DF ֌ ^݀<{^pAr^YwUml|I<9Y\G>|xԞajHwR(A;DXiɞ韖nER!mbՇ4 ,quٸesӥKLt*!ݧ9>'WNZf/鬃w򵖎](D g@!9
{
"licenseKey":"552258f2-1f24-43f9-914a-de3c4ff21b88",
"devtools_port":9090,
"runtime":{
"arguments":"",
"version":"18.87.55.19",
"fallbackVersion":"",
"futureVersion":""
},
"platform":{
{
"licenseKey": "552258f2-1f24-43f9-914a-de3c4ff21b88",
"devtools_port": 9090,
"runtime": {
"arguments": "",
"version": "18.87.55.19",
"fallbackVersion": "",
"futureVersion": ""
},
"platform": {
{
"licenseKey": "552258f2-1f24-43f9-914a-de3c4ff21b88",
"devtools_port": 9090,
"runtime": {
"arguments": "",
"version": "18.87.55.19",
"fallbackVersion": "",
"futureVersion": ""
},
"platform": {
from collections import defaultdict
def getAdjList(numNodes, fromList, toList):
adjList = [[] for _ in range(numNodes + 1)]
for u, v in zip(fromList, toList):
adjList[u].append(v)
adjList[v].append(u)
return adjList