Stonks-in-Hand / 02
Design decisions.
Technology choices, architecture options and how the design evolved.
Technology choices
The components considered before the architecture was selected.
Frontend
Meteor offered integrated real-time updates and rapid prototyping. React offered flexibility and a broad ecosystem, while Next.js added routing, server rendering and static generation. Next.js was selected for the application-oriented frontend; the later architecture used static delivery.
Backend
Meteor and Express kept the stack in JavaScript; Django provided an integrated Python framework. FastAPI was selected for a lightweight API and access to Python libraries for scraping, NLP and AI. Its flexibility also means authentication, deployment and operational choices must be made explicitly.
Database and API
PostgreSQL was preferred for relational data, joins and source traceability, with JSONB available for less-structured records. MongoDB was considered for flexible document storage. REST was chosen for a straightforward API; WebSockets and GraphQL offered capabilities that were not necessary for the core workflow.
Collection
Playwright and Selenium can handle JavaScript-rendered pages, at a higher resource cost than direct HTTP parsing. BeautifulSoup suits static pages; Scrapy offers a larger crawling framework. PRAW provides a Python interface to Reddit. Source access, rate limits and terms need to be respected.
AI and hosting
The original comparison considered hosted and open-weight models alongside local inference, weighing summarisation, structured output, cost, privacy and operational requirements. It also compared database and application hosting across Supabase, Neon, RDS, MongoDB Atlas, Railway, Render, EC2, Cloud Run and Galaxy.
Product tiers, model availability and pricing change. Historical estimates in the original evaluation are not current price quotes; the right choice depends on workload, region and present service limits.
Architecture options
Four candidate stacks, evaluated against traceability, AI processing, reliability and cost.
01 · Meteor and MongoDB
Meteor, React, MongoDB and Galaxy offered a unified JavaScript stack, built-in real-time synchronisation and quick prototyping. The trade-off was less direct access to the Python tooling needed for scraping and NLP; a separate service could address that at the cost of another integration. Resource limits were also a concern.
02 · Vercel, Railway and Supabase
A Next.js frontend, FastAPI backend and managed PostgreSQL split responsibilities across services. It offered a quick path to a Python-based API with less infrastructure management. The evaluation identified multi-platform configuration, compute limits, background-work costs and storage limits as risks.
03 · AWS and Python
The original recommendation combined Next.js and FastAPI on EC2, PostgreSQL on RDS, Docker, S3 and CloudFront. It offered control over the environment and support for longer-running workers, with greater responsibility for configuration, security and ongoing compute cost.
04 · AWS serverless
The serverless option used Lambda, API Gateway, S3 and CloudFront around the same Python and PostgreSQL foundations. It reduced the need to manage servers and could scale with demand, while introducing distributed debugging, execution limits and infrastructure complexity. The later milestone developed this into an event-driven pipeline.
What changed
The initial conclusion favoured EC2 and RDS for flexibility and long-running workloads. The Milestone 3 design moved to Lambda, SQS, S3 and Supabase after splitting work into event-driven stages. The change trades a simpler always-on environment for more services, independent retries and lower estimated idle cost.
Architectural decisions
The choices, alternatives and trade-offs that shaped the system.
01 · PostgreSQL for traceability
Context: users need structured watchlists and a way to connect claims to source material. Decision: use PostgreSQL and relational relationships, with JSONB where useful. Trade-off: the schema needs design and migrations, but joins make source and result relationships easier to express.
02 · FastAPI and Python
Context: the API needs to work with Python-based collection and NLP tooling. Decision: use FastAPI and typed request validation. Trade-off: the framework is lightweight, but the team must explicitly design authentication, deployment and service boundaries.
03 · REST for the core API
Context: the core frontend needs predictable requests and responses. Decision: use REST. WebSockets and GraphQL remain alternatives for specific real-time or query requirements, but add design and operational complexity.
04 · Event-driven processing
Context: scraping, downloads and analysis can be slow or fail independently. Decision: separate discovery, download, analysis and notifications into functions and queues. Consequence: work can be retried per stage and users need not wait for processing, but tracing failures across services requires deliberate observability and idempotent handling.
05 · S3 and Supabase
Context: raw documents and relational application records have different storage needs. Decision: store raw files in S3 and application data in Supabase PostgreSQL. Consequence: object storage and database costs and access controls must be managed separately.
06 · Serverless infrastructure
Context: the original EC2/RDS design incurred ongoing compute cost. Decision: move the later design to Lambda and managed event services. The document estimated a reduction from about $50 to under $10 per month for its assumed workload; this is an estimate, not a measured saving or a current pricing guarantee. More services and execution constraints are the principal trade-offs.
Designing for repeated work
Queues solve a scheduling problem: they let the producer finish without waiting for a slow consumer, buffer bursts and give each stage its own retry boundary. They also introduce a consistency problem. A database update, a message send and a downstream side effect can fail at different times; idempotency, status tracking and recovery need to be designed around those boundaries.
Keeping files in object storage also avoids putting large documents into queue messages or worker disks. A structured record can point back to the object and carry the processing status, while the queue carries a reference to the next task.
Measuring the trade-off
The original comparison estimated that the change from an always-on option could reduce monthly infrastructure cost from roughly $50 to under $10 for its assumed workload. That was a planning estimate rather than a measured bill. A credible new comparison should use the same region, request and document volumes, storage, retention and availability requirements for each option.
Milestones and operations
How the design changed as the application took shape.
Initial recommendation
The potential solution architecture first recommended Next.js, FastAPI, PostgreSQL and EC2. It prioritised control over compute for scraping and AI processing, with infrastructure as code and cost alerts to manage setup and spending risks.
Milestone 2
The implementation followed the proposed Next.js, FastAPI, REST, Pydantic, SQLAlchemy, PostgreSQL, Playwright and PRAW direction. CSS modules replaced the proposed Tailwind styling; Groq was used for some language-model tasks. The document described WebSockets as a possible later addition.
Milestone 3
The architecture changed to Lambda, API Gateway, S3 and CloudFront, with Supabase PostgreSQL and independent queued processing stages. EventBridge schedules collection; Bedrock supports summaries; Brevo handles email. Dead-letter queues and CloudWatch support investigation and monitoring.
Delivery and risk
GitHub Actions, SAM and CloudFormation make changes repeatable and support separate frontend and backend rollback. Runtime credentials stay outside source code. The move reduces always-on compute but increases the number of service boundaries, making logs, alarms, retries and cost monitoring central to the design.